Skip to content

Instantly share code, notes, and snippets.

@PaulC91
PaulC91 / paris_trees.R
Created November 15, 2017 15:09
R script to chart and map Paris tree data
library(tidyverse)
library(lubridate)
library(stringr)
library(hrbrthemes)
library(sf)
library(leaflet)
# R script to chart and map Paris tree data
# data available here https://opendata.paris.fr/explore/dataset/les-arbres/ ----------------
@PaulC91
PaulC91 / app.R
Created January 27, 2018 13:10
dynamic data transforms + input options in shiny for Gokhan
library(shinydashboard)
library(dplyr)
ui <- navbarPage("test",
tabPanel("dataBuilder", icon = icon("database"),
fluidRow(
box(width = 3, title = "Data Upload", solidHeader = TRUE, status = "primary",
helpText("Choose CSV File (Max size 10 MB)"),
fileInput("file1", "",
multiple = FALSE,
@PaulC91
PaulC91 / sankey.R
Last active March 4, 2018 10:22
Example of using function to create d3 sankey diagram from multiple categorical variables + one numerical value variable of tidy data frame
library(tidyverse)
library(tidygraph)
library(igraph)
library(networkD3)
# https://www.kaggle.com/unitednations/refugee-data/data
asylum_seekers_raw <- read_csv("asylum_seekers.csv")
# get the top 10 countries of origin by 'Total decisions'
top_orig <- asylum_seekers_raw %>%
@PaulC91
PaulC91 / party_points.R
Created April 2, 2018 11:37
How to map multivariate dot-density data with the R simple features package and ggplot2
library(tidyverse) # dev version of ggplot2 required devtools::install_github('hadley/ggplot2')
library(sf)
extrafont::loadfonts(device = "win")
# election results
ge_data <- read_csv("http://researchbriefings.files.parliament.uk/documents/CBP-7979/HoC-GE2017-constituency-results.csv") %>%
filter(region_name == "London") %>%
select(ons_id, constituency_name, con:green)
library(tidyverse)
library(sf)
#https://www.cultureofinsight.com/blog/2018/05/02/2018-04-08-multivariate-dot-density-maps-in-r-with-sf-ggplot2/
svk.dot <- st_read("shp/hranice_obce_3.shp", stringsAsFactors = FALSE, quiet = TRUE) %>%
st_transform(4326)
colnames(svk.dot)[1] <- "id"
@PaulC91
PaulC91 / gs_auth.R
Last active June 12, 2018 10:42
googlesheets setup for shiny
library(googlesheets)
# do this initially to save your token in the app's working direcotory
# once it's saved you can comment this code out
token <- gs_auth(cache = FALSE)
saveRDS(token, file = "googlesheets_shiny_token.rds")
# then this code in your app will authenticate and read in a workbook of your choice each time it's loaded
gs_auth(token = "googlesheets_shiny_token.rds")
sheet_key <- "your_google_sheet_key_here"
@PaulC91
PaulC91 / discogger_geo.R
Last active June 12, 2018 16:35
map your record collection with the discogger R package
library(discogger)
library(tidyverse)
library(sf)
library(rnaturalearth)
library(countrycode)
library(scico)
my_records <- discogs_user_collection("pacampbell91")
my_releases <- map_chr(my_records$content, "id") %>%
@PaulC91
PaulC91 / network_wc.R
Last active July 19, 2018 13:28
network graph of world cup players connected by club and country
library(rvest)
library(tidyverse)
library(tidygraph)
library(ggraph)
wc_squads <- html("https://en.wikipedia.org/wiki/2018_FIFA_World_Cup_squads")
tables <- wc_squads %>%
html_table()
@PaulC91
PaulC91 / wc_network.R
Created June 14, 2018 11:03
network graph of world cup players countries and clubs
library(rvest)
library(tidyverse)
library(tidygraph)
library(ggraph)
wc_squads <- read_html("https://en.wikipedia.org/wiki/2018_FIFA_World_Cup_squads") %>%
html_table()
teams <- c("Egypt", "Russia", "Saudi Arabia", "Uruguay",
"Iran", "Morocco", "Portugal", "Spain",
@PaulC91
PaulC91 / purrr_ppt.R
Last active October 2, 2019 23:18
Example of programming powerpoint slides using purrr::walk and the officer package
library(tidyverse)
library(officer)
library(mschart)
# create new ppt with title slide
mypres <- read_pptx() %>%
add_slide(layout="Title Slide", master="Office Theme") %>%
ph_with_text(type = "ctrTitle", str = "Make slide decks with purrr & officer") %>%
ph_with_text(type = "subTitle", str = "example using mtcars data")