Skip to content

Instantly share code, notes, and snippets.

View jakeybob's full-sized avatar
🤦‍♂️
ARGH

Bob Taylor jakeybob

🤦‍♂️
ARGH
View GitHub Profile
@jakeybob
jakeybob / generate_scot_std_pop_daily.R
Created June 7, 2021 20:22
Scotland standardised age/sex interpolated populations
library(tidyverse)
library(janitor)
library(lubridate)
library(zoo)
library(ckanr)
# generates age/sex population lookup for Scotland based on NRS mid-year
# population estimates/projections, interpolated linearly to day level
# (July 2nd used as mid-year reference date).
#
@jakeybob
jakeybob / generate_scot_pop_daily.R
Created June 5, 2021 19:54
Scotland age/sex interpolated population estimates/projections
library(tidyverse)
library(janitor)
library(lubridate)
library(zoo)
library(ckanr)
# generates age/sex population lookup for Scotland based on NRS mid-year
# population estimates/projections, interpolated linearly to day level
# (July 2nd used as mid-year ref date)
@jakeybob
jakeybob / openair.R
Created September 28, 2020 18:48
Glasgow / Scotland air quality trends etc
library(openair)
library(tidyverse)
library(lubridate)
#### SETUP ####
saqn_meta <- importMeta(source = "SAQN", all = TRUE) # metadata for all the Scottish Air Quality Network sites
years <- 1987:2019 # NO2 trend goes back to 1987 for Glasgow City Chambers
glasgow_saqn_sites_pm10 <- c("Glasgow Abercromby Street",
"Glasgow Anderston",
library(tidyverse)
library(stats19)
library(ckanr)
# libs for mapping accident lat/long to datazone for Glasgow deprivation analysis
library(sf)
library(rmapshaper)
# below libs useful for speeding up mapping accidents over water to nearest datazone
library(foreach)
library(doParallel)
registerDoParallel(parallel::detectCores())
@jakeybob
jakeybob / xmas_gifts.R
Created December 18, 2019 12:16
N Days of Christmas
xmas_gifts <- function(days=12, pear_tree=FALSE){
days <- abs(as.integer(days))
gifts <- 0
# for(i in 1:days){gifts <- gifts + i*(days + 1 - i)} # general case: does N=days total summations
# can ~half the number of summations because...
# if days = even, summation is symmetric and reduces to e.g. 2*[12x1 + 11x2 + 10x3 + 9x4 + 8x5 + 7x6] for 12 total days
for(i in 1:(days/2 - .5* days %% 2)){
@jakeybob
jakeybob / ray.R
Created July 10, 2019 09:08
Rayshader Test | Scotland Inpatients (Oct – Dec 2018)
# remotes::install_github("tylermorganwall/rayshader")
library(rayshader) # rayshader_0.11.4
library(ggplot2)
library(sf)
library(tidyverse)
library(rmapshaper)
library(viridis)
#### DATA IMPORT ####
# inpatient numbers, by health board, Oct-Dec 2018
@jakeybob
jakeybob / gauss_v_poisson_CI.R
Created May 18, 2019 17:34
Animation of Gaussian and Poissonian functions and their confidence intervals
library(tidyverse)
library(ggplot2)
library(survival)
lambdas <- seq(300, 2)
pic_dir <- "pics"
fps <- 24
output_video <- "output.mp4"
# construct dataframes
@jakeybob
jakeybob / clifford_attractor_animation.R
Last active May 2, 2019 19:17
R script for generating animated Clifford attractors
library(Rcpp)
library(ggplot2)
library(dplyr)
library(foreach)
library(doParallel)
registerDoParallel(parallel::detectCores())
pic_dir <- "pics"
output_video <- "output.mp4"
@jakeybob
jakeybob / openair_pollution.R
Last active April 13, 2019 16:51
OpenAir Pollution Animation
library(openair)
library(tidyverse)
library(lubridate)
library(gganimate)
jhn <- as_tibble(importSAQN(site = "REN02", year = 2017:2019, pollutant = "all")) %>%
mutate(day = date(date))
# saveRDS(jhn, "jhn.rds")
# jhn <- readRDS("jhn.rds")
@jakeybob
jakeybob / spectrogram_video.R
Created March 16, 2019 13:24
R script for creating spectrogram videos from .wav files
library(seewave)
library(ggplot2)
library(scales)
library(foreach)
library(doParallel)
registerDoParallel(parallel::detectCores())
#### SETUP ####
file_wav <- "firestarter16.wav"
pic_dir <- "pics"