Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
Last active October 16, 2021 03:09
Show Gist options
  • Save thoughtfulbloke/0fa2d25e43fe3eeb843f61d8a8140b6e to your computer and use it in GitHub Desktop.
Save thoughtfulbloke/0fa2d25e43fe3eeb843f61d8a8140b6e to your computer and use it in GitHub Desktop.
vaxathon progress code
library(dplyr)
library(tidyr)
library(ggplot2)
library(ggthemes)
library(scales)
library(lubridate)
library(rvest)
system_time= paste("Update: ", Sys.time())
txt_data <- "
dhb, pop12+,dosed2
Auckland Metro,1432761,909704
Bay of Plenty,216874,110817
Canterbury,482847,249722
Capital & Coast and Hutt Valley,401349,233540
Hawkes Bay,145495,83801
Lakes,94376,50214
MidCentral,152257,83563
Nelson Marlborough,135658,89904
Northland,161256,82668
Overseas / Unknown,17101,36399
South Canterbury,52526,30810
Southern,287955,181410
Tairawhiti,41906,22499
Taranaki,102093,50578
Waikato,357116,207195
Wairarapa,41362,24489
West Coast,27842,14869
Whanganui,57198,32142"
primary_url <- "https://covid19.govt.nz/covid-19-vaccines/how-to-get-a-covid-19-vaccination/super-saturday/super-saturday-numbers/"
h <- html_text(read_html(primary_url))
h1 <- gsub(".*Total doses across New Zealand\n\nLast updated", "Total doses across New Zealand\n\nLast updated", h)
h2 <- gsub("Back to top.*", "Back to top", h1)
sections = strsplit(h2,split="\n\n\n\n\n\n")
dhbs <- unlist(sections[[1]][[5]])
dhb_individual <- unlist(strsplit(dhbs,split="\n\n\n\n\n"))
running <- data.frame(dhb_individual) %>%
separate(dhb_individual, into=c("numberD", "DHB"), sep="\n") %>%
mutate(doses_total = as.numeric(gsub(",","",numberD)),
dhb = case_when(DHB == "Northland" ~ "Northland",
DHB == "Auckland" ~ "Auckland Metro",
DHB == "Waitematā" ~ "Auckland Metro",
DHB == "Counties Manukau" ~ "Auckland Metro",
DHB == "Bay of Plenty" ~ "Bay of Plenty",
DHB == "Waikato" ~ "Waikato",
DHB == "Lakes" ~ "Lakes",
DHB == "Tairāwhiti" ~ "Tairawhiti",
DHB == "Hawke's Bay" ~ "Hawkes Bay",
DHB == "MidCentral" ~ "MidCentral",
DHB == "Taranaki" ~ "Taranaki",
DHB == "Whanganui" ~ "Whanganui",
DHB == "Wairarapa" ~ "Wairarapa",
DHB == "Hutt Valley" ~ "Capital & Coast and Hutt Valley",
DHB == "Wellington" ~ "Capital & Coast and Hutt Valley",
DHB == "Nelson Marlborough" ~ "Nelson Marlborough",
DHB == "Canterbury" ~ "Canterbury",
DHB == "South Canterbury" ~ "South Canterbury",
DHB == "West Coast" ~ "West Coast",
DHB == "Southern" ~ "Southern",
DHB == "Other" ~ "Other")) %>%
group_by(dhb) %>%
summarise(doses_today = sum(doses_total))
base_line <- read.csv(text=txt_data, stringsAsFactors = FALSE)
gdat <- inner_join(base_line,running) %>%
mutate(percent_of_remaining = 100 * doses_today / (pop12. - dosed2))
g1 <- ggplot(gdat, aes(x=dhb,y=percent_of_remaining)) +
geom_col(width=.65) + coord_flip() +
labs(title="Vaxathon - percent of people possible to\nvaccinate on the 12th\nwho have been vaccinated today", x="Area", y="Percentage of remaining eligable", caption=system_time) +
geom_text(aes(label=round(percent_of_remaining,1)), size=3, hjust=1, colour="white", nudge_y = -.1)
#g1
davidise_graph(g1)
print(paste(sum(running$doses_today), " doses"))
print(paste(100 * sum(running$doses_today)/ 93350, " percent of best day in history"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment