Created
October 3, 2023 17:24
-
-
Save mikebirdgeneau/9ed151b7ea4a0fe4d7d9d76fc683a2b8 to your computer and use it in GitHub Desktop.
Alberta COVID19 Wastewater Chart in R
This file contains hidden or 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(data.table) | |
library(jsonlite) | |
library(ggplot2) | |
library(jsonlite) | |
library(glue) | |
tmpfile <- tempfile(fileext = ".json") | |
download.file("https://chi-covid-data.pages.dev/aplWasteWaterAbData.json",tmpfile) | |
json_data <- jsonlite::read_json(tmpfile)$data | |
unlink(tmpfile) | |
rm(tmpfile) | |
data <- rbindlist(lapply(names(json_data),function(x,data=json_data){ | |
cbind(rbindlist(data[[x]]),location=x) | |
})) | |
rm(json_data) | |
data[,date:=as.Date(date)] | |
p <- ggplot(data,aes(x=date))+ | |
geom_step(aes(y=avg),alpha=0.5)+ | |
geom_point(aes(y=avg))+ | |
stat_smooth(aes(y=avg))+ | |
facet_wrap(~location,scales = "free_y")+ | |
scale_y_continuous(name="Viral Copies per Person")+ | |
scale_x_date(name=NULL, | |
date_breaks="1 month", | |
date_labels = "%b", | |
date_minor_breaks = "1 week")+ | |
theme_bw()+ | |
labs(title="Alberta: COVID19 in Wastewater", | |
subtitle=glue::glue("Latest Data as of: {max(data$date,na.rm=T)}"), | |
caption=glue::glue("Data Source: Alberta Health, Alberta Precision Laboratories & Centre for Health Informatics\n{Sys.Date()}") | |
) | |
ggsave(glue::glue("{Sys.Date()}_-_COVID19_Wastewater.png"),plot=p,units="in",width=6,height=4,dpi=150,scale = 1.2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment