Skip to content

Instantly share code, notes, and snippets.

@tslumley
Last active July 24, 2021 04:55
Show Gist options
  • Save tslumley/8bc76ee18aef1937de3ba46f4974d4c0 to your computer and use it in GitHub Desktop.
Save tslumley/8bc76ee18aef1937de3ba46f4974d4c0 to your computer and use it in GitHub Desktop.
Hexbins of NZ Covid vaccination
library(rvest)
library(dplyr)
library(DHBins)
a<-read_html("https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-data-and-statistics/covid-19-vaccine-data")
a %>%
html_node("body") %>%
xml2::xml_find_all("//table") %>% nth(n=3) %>%html_text() ->b
gsub("\t"""strsplit(b"\n")[[1]]fixed=TRUE)->d
e<-as.data.frame(matrix(d[4:63]ncol=3,byrow=TRUE))
names(e)<-c("DHB""First""Second")
e[[2]]<-as.numeric(e[[2]])
e[[3]]<-as.numeric(e[[3]])
## From Subnational population estimates at 30 June 2020; nzdotstat
pop<-c(Northland=194600,
Waitemata=
639500,
Auckland=
505400,
"Counties Manukau"=
595100,
Waikato=
438300,
Lakes=
117400,
"Bay of Plenty"=
263900,
Tairawhiti=
50700,
Taranaki=
124700,
"Hawkes Bay"=
178500,
Whanganui=
68500,
"MidCentral"=
187300,
"Hutt Valley"=
158900,
"Capital and Coast"=
324400,
"Wairarapa"=
48900,
"Nelson Marlborough"=
161200,
"West Coast"=
32400,
Canterbury=
582700,
"South Canterbury"=
62000,
Southern=
349700)
e[[4]]<-pop[order(names(pop))]
names(e)[4]<-"Pop"
tri<-tri_alloc(cbind(e[[4]]-e[[2]],e[[2]]-e[[3]],e[[3]]),names=e[[1]],colours=c("None","First","Second"))
tri_data<-data.frame(DHB=e[[1]],vax=as.vector(tri),tri_id=rep(1:6,each=nrow(e)))
tri_data$vax<-factor(tri_data$vax,levels=c("None","First","Second"))
ggplot(tri_data)+
geom_dhb(aes(map_id=dhb_fixname(DHB)),fill="white",colour="grey",coord=FALSE)+
geom_dhbtri(aes(map_id=DHB,class_id=tri_id, fill=vax),alpha=0.5)+
scale_fill_manual(values=c("white","goldenrod","forestgreen"))+
geom_label_dhb(short=TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment