Created
January 1, 2022 04:01
-
-
Save thoughtfulbloke/52f1810bd8b777a99d3d839481ce88e5 to your computer and use it in GitHub Desktop.
Code for showing no community spread of omicron at present
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readr) | |
library(dplyr) | |
library(ggplot2) | |
library(ggthemes) | |
library(lubridate) | |
source("davidise.R") # graph styling and saving at twitter size | |
# extract colorblind pallete in case I want to make strategic use of it | |
six_cols <- (colorblind_pal()(6)) | |
# daily full demographic csvs folder | |
cases_folder <- list.files("daily_all_cases", pattern = "csv$", full.names = TRUE) | |
all_csvs <- file.info(cases_folder) | |
# find most recently saved csv file | |
latest_csv <- row.names(all_csvs)[which.max(all_csvs$ctime)] | |
all_cases <- read_csv(latest_csv, col_types= cols( | |
`Report Date` = col_date(format = ""), | |
.default = col_character())) %>% | |
filter(`Report Date` > (max(`Report Date`) - days(14))) %>% | |
count(Date = `Report Date`, DHB) %>% | |
group_by(DHB) %>% | |
mutate(entries = n()) %>% | |
ungroup() %>% | |
filter(entries >1) %>% | |
mutate(log2y=log(n,2), | |
Date2=as.numeric(Date)) | |
bookends = c(min(all_cases$Date2),max(all_cases$Date2)) | |
bookendsD = format.Date(c(min(all_cases$Date),max(all_cases$Date)), | |
format="%b\n%d") | |
bookendsT = format.Date(c(min(all_cases$Date),max(all_cases$Date)), | |
format="%b %d") | |
leads <- all_cases %>% filter(n > 19) | |
if_doubling <- function(x, cvdata=leads){ | |
xinput <- cvdata$Date2[x] | |
yinput <- cvdata$n[x] | |
zinput <- cvdata$DHB[x] | |
xguide = 1:1600/100 | |
yguide <- (2^(1/2))^(xguide-1) | |
xcord <- xguide[yguide > yinput & yguide < 100] | |
xcord <- xcord - min(xcord) + xinput | |
ycord <- yguide[yguide > yinput & yguide < 100] | |
dat <- data.frame(xcord, ycord,group_id = paste0(xinput,zinput), | |
DHB=zinput, stringsAsFactors = FALSE) | |
return(dat) | |
} | |
result_guide <- bind_rows(lapply(1:nrow(leads), if_doubling)) | |
dg <- ggplot(all_cases, aes(x=Date2, y=n)) + | |
geom_line(data=result_guide, | |
aes(x=xcord,y=ycord,group=group_id), | |
size=0.4, colour="#BFBFBF") + | |
geom_point(size=0.6) + | |
facet_wrap(~DHB, ncol=4) + | |
theme_tufte() + | |
scale_x_continuous(breaks = bookends, | |
labels = bookendsD) + | |
labs(title="DHB daily cases with Omicron doubling time guide lines\n(Omicron doubling guides for 20+ case days)", | |
subtitle=paste("for the two week period", bookendsT[1],"to",bookendsT[2]), | |
y="Number of cases\n", x="") | |
dg | |
davidise_graph(dg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment