Skip to content

Instantly share code, notes, and snippets.

View google_covid_mobility_scraper.R
# Install and load required packages
install.packages("needs")
library(needs)
needs(tidyverse, magrittr, animation, pdftools, png, scales)
# Function that extracts data from Google Mobility PDFs
process_google_mobility <- function(country_code, start_date, end_date){
# Convert first page of PDF into high-res PNG
pdf_convert(paste0("https://www.gstatic.com/covid19/mobility/",end_date,"_",country_code,"_Mobility_Report_en.pdf"), format = "png", pages = 1, dpi = 300, filenames = "IMG1.png")
@johnburnmurdoch
johnburnmurdoch / .block
Last active Dec 21, 2020
Watercolour affect using HTML5 canvas
View .block
license: mit
height: 620
scrolling: no
border: no
@johnburnmurdoch
johnburnmurdoch / .block
Last active Dec 21, 2020
Tool for creating virtual spray paint / masking tape art
View .block
height: 700
View covid_cases_script.R
install.packages("needs")
library(needs)
needs(tidyverse, magrittr, rvest, zoo, scales)
WHO_sars_links <- read_html("https://www.who.int/csr/sars/country/en/") %>%
html_nodes("ul.auto_archive") %>%
magrittr::extract(1) %>%
html_nodes("li a") %>%
map_dfr(~{
link <- .x %>% html_attr("href") %>% paste0("https://www.who.int",.)
View covid_cases_UK_LAs.csv
area_name per_week_per_100k pop
Aragon 194 1344184
Navarra 154 633017
Catalonia 921 7463471
Basque Country 136 2179532
La Rioja 12 319939
Madrid 229 6373532
Valencia 128 4989631
Extremadura 10 1096421
Murcia 67 1453545
@johnburnmurdoch
johnburnmurdoch / defaultData.csv
Last active May 28, 2020 — forked from phil-pedruco/defaultData.csv
3D Scatter Plot Using three.js
View defaultData.csv
x y z lp_x lp_y lp_z hp_x hp_y hp_z
0.235458 -0.597702 -0.724487 0.232433 -0.593757 -0.717156 0.003025 -0.003945 -0.007332
0.235458 -0.597702 -0.724487 0.232735 -0.594152 -0.717889 0.002723 -0.003550 -0.006598
0.217346 -0.597702 -0.724487 0.231197 -0.594507 -0.718549 -0.013850 -0.003195 -0.005939
0.217346 -0.579590 -0.724487 0.229812 -0.593015 -0.719143 -0.012465 0.013425 -0.005345
0.199234 -0.579590 -0.724487 0.226754 -0.591673 -0.719677 -0.027520 0.012083 -0.004810
0.199234 -0.597702 -0.760712 0.224002 -0.592276 -0.723781 -0.024768 -0.005426 -0.036931
0.163010 -0.579590 -0.706375 0.217903 -0.591007 -0.722040 -0.054893 0.011417 0.015665
0.108673 -0.597702 -0.724487 0.206980 -0.591676 -0.722285 -0.098307 -0.006026 -0.002203
0.090561 -0.615814 -0.724487 0.195338 -0.594090 -0.722505 -0.104777 -0.021724 -0.001982
View coronavirus_cases_trajectories.R
read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv") %>%
gather(date, cases, 5:ncol(.)) %>%
mutate(date = as.Date(date, "%m/%d/%y")) %>%
group_by(country = `Country/Region`, date) %>%
summarise(cases = sum(cases)) %>%
filter(country != "Others" & country != "Mainland China") %>%
bind_rows(
tibble(country = "Republic of Korea", date = as.Date("2020-03-11"), cases = 7755)
) %>%
group_by(country) %>%
View ireland_consituency_results_map.R
install.packages("needs")
library(needs)
needs(tidyverse, magrittr, rvest, sf, raster, rgdal)
ireland_constits <- c("https://en.wikipedia.org/wiki/Carlow%E2%80%93Kilkenny_(D%C3%A1il_constituency)") %>%
read_html() %>%
html_nodes('div[aria-labelledby="Current_Dáil_constituencies"] tr:nth-child(2) ul li a') %>%
html_attr("href") %>%
tail(-1) %>%
c("/wiki/Carlow%E2%80%93Kilkenny_(D%C3%A1il_constituency)", .)
View city_populations_projections.csv
year value name group lastValue subGroup lat lon city_id
1575 200 Agra India 200 India 27.18333 78.01667 Agra - India
1576 212 Agra India 200 India 27.18333 78.01667 Agra - India
1577 224 Agra India 212 India 27.18333 78.01667 Agra - India
1578 236 Agra India 224 India 27.18333 78.01667 Agra - India
1579 248 Agra India 236 India 27.18333 78.01667 Agra - India
1580 260 Agra India 248 India 27.18333 78.01667 Agra - India
1581 272 Agra India 260 India 27.18333 78.01667 Agra - India
1582 284 Agra India 272 India 27.18333 78.01667 Agra - India
1583 296 Agra India 284 India 27.18333 78.01667 Agra - India
View extract_values_from_bar_charts.R
needs(tidyverse, magrittr, png)
# Create a folder for storing the charts
dir.create("BFB_images")
# Loop though constituency codes in England and Wales, downloading the chart for each on from BfB
for(pcon in c(B4B_MRP$westminster_constituency[B4B_MRP$region != "Scotland"])){
tryCatch(download.file(paste0("https://www.getvoting.org/charts/",pcon,"_1.png"), destfile = paste0("BFB_images/", pcon, ".png")), error = function(e){message("No chart")})
}