Last active
December 16, 2021 14:08
-
-
Save lvalnegri/96e4b8be3121a8d8e4889f423649f726 to your computer and use it in GitHub Desktop.
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
# Total Cases: https://coronavirus.data.gov.uk/ (updated after 4PM at minimum) | |
# Omicron split: https://www.gov.uk/government/publications/covid-19-omicron-daily-overview (updated at ?) | |
library(data.table) | |
library(ggplot2) | |
yc <- fread( | |
'https://api.coronavirus.data.gov.uk/v2/data?areaType=region&metric=newCasesBySpecimenDate&format=csv', | |
select = c(2, 4, 5) | |
) | |
setnames(yc, c('RGN', 'sdate', 'n')) | |
y <- fread( | |
paste0( | |
'https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/1041217/sgtf_regionepicurve_', | |
(Sys.Date() - 1), | |
'.csv' | |
), | |
select = 1:5 | |
) | |
setnames(y, c('RGN', 'sdate', 'n_sgtf', 'p_sgtf', 'sgtf')) | |
y <- y[grepl('SGTF', sgtf)][, sgtf := NULL] | |
y[RGN == 'Yorkshire and Humber', RGN := 'Yorkshire and The Humber'] | |
y[, sdate := as.IDate(sdate, '%d/%m/%Y')] | |
y <- yc[y, on = c('RGN', 'sdate')] | |
y[, omicron := as.integer(n * p_sgtf / 100)][, others := n - omicron] | |
y <- melt(y[, .(RGN, sdate, omicron, others)], id.vars = 1:2, variable.name = 'variant', value.name = 'cases') | |
ggplot(y, aes(sdate, cases, color = variant)) + | |
geom_line() + | |
facet_wrap(~RGN) + | |
labs(x = 'Specimen Date', y = 'Cases') + | |
theme_minimal() + | |
theme(axis.text.x=element_text(angle = 45, hjust = 1)) + | |
scale_x_date(date_breaks = '1 week', date_labels = '%d %b') + | |
scale_y_continuous(label = scales::comma) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment