Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
thoughtfulbloke / KnKplus.R
Created March 11, 2024 08:07
KnKplusGibson
library(dplyr)
library(tidyr)
library(lubridate)
NZstmf <- read.csv("NZL_NPstmfout.csv") |>
filter(Sex == "b")
NZQTR <- read.csv("TotalQuarterlyPopulationAsAt.csv", skip=3,
col.names = c("YRQR","Pop")) |>
filter(!is.na(Pop)) |>
separate(YRQR, into=c("YR", "QR"), sep="Q", convert = TRUE) |>
mutate(asDate = ceiling_date(ISOdate(YR,QR*3,25),
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 20 columns, instead of 18. in line 7.
"Age-specific death rates by sex, December years (total population) (Annual-Dec)","","","","","","","","","","","","","","","","","","",""
"","Total Population","","","","","","","","","","","","","","","","","",""
" ","0-4 Years","5-9 Years","10-14 Years","15-19 Years","20-24 Years","25-29 Years","30-34 Years","35-39 Years","40-44 Years","45-49 Years","50-54 Years","55-59 Years","60-64 Years","65-69 Years","70-74 Years","75-79 Years","80-84 Years","85-89 Years","90 Years and Over"
1971,4.31,0.39,0.35,0.96,1.06,0.97,1.29,1.81,2.93,4.70,7.50,12.19,19.17,29.34,44.81,71.51,118.74,192.62,280.73
1972,4.04,0.37,0.33,1.16,1.13,0.89,1.19,1.71,2.65,4.51,7.33,11.72,19.32,29.64,45.89,74.35,118.35,187.90,309.62
1973,3.99,0.42,0.35,1.22,1.24,0.98,1.17,1.86,2.70,4.76,7.26,12.57,18.57,30.31,45.92,72.05,114.84,190.45,320.67
1974,3.68,0.38,0.43,1.16,1.06,1.04,1.15,1.76,2.96,4.74,7.51,11.68,19.02,28.10,46.32,70.63,111.84,190.96,314.86
1975,3.78,0.46,0.34,1.02,1.11,1.01,1.17,1.75,2.64,4.60,7.39,11.07,19.04,27.29,45.13,65.78,106
library(rmapshaper)
library(sf)
library(ggplot2)
library(dplyr)
library(patchwork)
# geographic data from koordinates.com
start_map <- read_sf("new-zealand-2018-estimated-resident-population-statistical-g/new-zealand-2018-estimated-resident-population-statistical-g.shp")
coast <- read_sf("nz-coastlines-and-islands-polygons-topo-150k/nz-coastlines-and-islands-polygons-topo-150k.shp")
# simplify the graph to what is visually useful
library(dplyr)
library(lubridate)
library(readr)
library(RcppRoll)
library(ggplot2)
library(ggthemes)
sixcols= colorblind_pal()(6)
case_counts <- read_csv("https://raw.githubusercontent.com/minhealthnz/nz-covid-data/main/cases/covid-case-counts.csv")
```{r}
library(readr)
library(dplyr)
library(lubridate)
```
David's usage notes for the wastewater data at: https://github.com/ESR-NZ/covid_in_wastewater
I am reading the files directly of github, rather than downloading and then reading locally.
library(rvest) # process web pages
library(dplyr) # general data pipeleine tools
library(lubridate) # date functions
# saving demographic pages as html into a folder
# called case_demografics_html_asof
# with a datestamp name for the contents
Demographs <- list.files("../case_demografics_html_asof", pattern=".*html$")
extract_vax <- function(x) {
# source this file so it pauses for input,
# check the graphs
# add comments via the readline input
# post using rtweet
library(rvest)
library(dplyr)
library(ggplot2)
library(lubridate)
library(rtweet)
library(rvest)
library(dplyr)
library(lubridate)
library(stringr)
library(readr)
library(ggplot2)
library(ggthemes)
library(RcppRoll)
sixcol <- colorblind_pal()(6)
@thoughtfulbloke
thoughtfulbloke / excess_mort_2022.R
Created May 6, 2022 01:49
Population Data from Infoshare (quarterly, as at, DPE). Deaths from StatsNZ open data API, but also in their Covid data portal
legpos="right"
theme_davidhood <- function(){
# theme_minimal(base_family="OpenSans") %+replace%
theme_minimal() %+replace%
theme(panel.grid = element_blank(),
axis.line.x = element_line(size=0.1),
axis.line.y = element_line(size=0.1),
axis.ticks = element_line(size=0.2),
strip.background = element_rect(fill= "#FFFFFF", colour="#EFEFEF"),
strip.text = element_text(size = 13,
library(rvest)
library(dplyr)
library(tidyr)
library(lubridate)
library(stringr)
library(readr)
library(ggplot2)
library(ggthemes)
library(patchwork)
source("davidise.R")