This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(gapminder) | |
library(openxlsx) | |
gm <- gapminder %>% | |
select(-continent) | |
# to get latest year as first tab in workbook | |
years <- unique(gm$year) %>% sort(decreasing = TRUE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rmarkdown) | |
library(ggplot2) | |
library(purrr) | |
ppt_render <- function (data) { | |
params <- list(data = data) | |
group <- unique(data$class) | |
rmarkdown::render("report.Rmd", output_file = paste0("mpg_", group, ".pptx"), params = params) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(officer) | |
library(mschart) | |
# function to make ppt deck for each class in mpg data | |
new_deck <- function (i) { | |
data <- mpg %>% | |
filter(class == i) | |
ppt_chart <- ms_scatterchart(data, x = "displ", y = "hwy", group = "cyl") %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |