Skip to content

Instantly share code, notes, and snippets.

library(readr)
library(suncalc)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(lubridate)
quake10yr <- c("https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2020-02-01&enddate=2021-03-01T0:00:00",
"https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2019-02-01&enddate=2020-02-01",
"https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2018-01-01&enddate=2019-02-01",
@thoughtfulbloke
thoughtfulbloke / NZMiQ_postivity.R
Created January 10, 2021 23:13
New Zealand MiQ covid positivity rate calculation
library(readxl)
library(readr)
library(dplyr)
library(lubridate)
library(ggplot2)
library(ggthemes)
# arrivals from provisional daily arrivals stats NZ
# postive MiQ data from MoH case demographics
# example code for processing the XML New Zealand elections final data
# party and cadidate vote.
# source: https://electionresults.govt.nz/electionresults_2020/xml/
#
# preceding this code was downloading a local copy of the NZ election
# XML provisional results using wget.
# Before that, since I am on a Mac, was using homebrew to install wget
# then I ran the terminal command
# wget -r -np -k https://electionresults.govt.nz/electionresults_2020/xml/
library(dplyr)
library(ggplot2)
library(ggthemes)
library(maps)
library(mapdata)
combined <- read.csv("combined.csv", stringsAsFactors = FALSE)
top_support <- max(combined$vote)
# keep in mind one polling place can provide for multiple electorates
@thoughtfulbloke
thoughtfulbloke / process_nz_2020_election.R
Created November 4, 2020 02:10
R code showing processing the xml data for the NZ 2020 general election
# example code for processing the XML New Zealand elections provisional data
# party vote only, but is extendable to cadidate vote.
# source: https://electionresults.govt.nz/electionresults_2020_preliminary/xml/
#
# preceding this code was downloading a local copy of the NZ election
# XML provisional results using wget.
# Before that, since I am on a Mac, was using homebrew to install wget
# then I ran the terminal command
# wget -r -np -k https://electionresults.govt.nz/electionresults_2020_preliminary/xml/
@thoughtfulbloke
thoughtfulbloke / DSTcheck.R
Last active October 28, 2020 21:37
Checks twitter accounts daylight savings movements.
# modify this line
questionable_screennames <- c("put","screennames","here")
###
library(rtweet)
library(dplyr)
library(lubridate)
library(ggplot2)
library(scales)
library(ggthemes)
library(readr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(ggthemes)
library(lubridate)
# because we have a lot of csv files of mentions, and only want a few columns
# from each, we will us a custom read function for each csv
custom_read <- function(x){
@thoughtfulbloke
thoughtfulbloke / impute_apple_mobility_missing_days.R
Last active August 28, 2020 20:14
Imputes the 11th and 12th of May in Apple Mobility Data
library(lubridate)
library(tidyr)
library(dplyr)
apple <- read.csv("~/Desktop/applemobilitytrends-2020-08-26.csv",
stringsAsFactors = FALSE)
# columns X2020.05.11 X2020.05.12 are missing, so for that Mon and Tue
# working out the median relationships between Sun and Wed and Mon and Tue
# and applying them using the Sun and Wed of that week.
library(dplyr)
library(tidyr)
library(lubridate)
library(ggplot2)
library(countrycode)
world <- readr::read_csv("https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/CSV_FILES/WPP2019_TotalPopulationBySex.csv")
pops <- world %>% filter(Variant == "Medium") %>%
mutate(country_code = countrycode(Location, origin = 'country.name', destination = 'iso3c')) %>%
select(year=Time, country_code, PopTotal)
mort <- readr::read_csv("https://www.mortality.org/Public/STMF/Outputs/stmf.csv", skip = 1) %>%
library(dplyr)
library(countrycode)
library(lubridate)
library(tidyr)
library(ggplot2)
library(ggthemes)
library(ggrepel)
# apple mobility data csv from
# https://www.apple.com/covid19/mobility
amt <- read.csv("~/Desktop/applemobilitytrends-2020-05-20.csv", colClasses = "character",