Skip to content

Instantly share code, notes, and snippets.

@dylanhmorris
Last active December 20, 2021 21:13
Show Gist options
  • Select an option

  • Save dylanhmorris/3ec25ad32a91ffbfed62cd90d340011d to your computer and use it in GitHub Desktop.

Select an option

Save dylanhmorris/3ec25ad32a91ffbfed62cd90d340011d to your computer and use it in GitHub Desktop.
library(tidyverse)
library(cowplot)
library(lubridate)
library(zoo)
sgtf_path <- "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/1042545/sgtf_regionepicurve_2021-12-19.csv"
sgtf <- read_csv(sgtf_path,
col_types = cols(
specimen_date = col_date())) %>%
mutate(variant = factor(
ifelse(sgtf == "Cases with confirmed S-gene",
"Delta and others",
"Omicron"),
ordered = TRUE)) %>%
group_by(UKHSA_region, variant) %>%
arrange(specimen_date, .by_group = TRUE) %>%
mutate(seven_day_avg = rollmean(n, 7,
na.pad = TRUE,
align = "center"),
week_over_week = n / lag(n, 7))
sgtf_title <- "Cases in England regions by specimen date and SGTF status"
sgtf_caption <- "Data: UKHSA\n\nBased on a plot by @theosanderson;\nzoomed log scale version by @dylanhmorris"
variant_colors <- c("#377eb8",
"#e41a1c")
plot <- sgtf %>% filter(specimen_date > today() - 21,
specimen_date <= max(specimen_date),
specimen_date <= today() - 4) %>%
ggplot(aes(x = specimen_date,
color = variant,
fill = variant,
y = n)) +
geom_point(size = 3,
alpha = 0.5,
color = "black",
shape = 21) +
geom_line(aes(y = seven_day_avg),
size = 2,
alpha = 0.9) +
labs(x = "Specimen date",
y = "Cases") +
theme_minimal() +
scale_x_date(breaks = scales::pretty_breaks(4)) +
scale_y_continuous(trans = "log10") +
scale_color_manual(values = variant_colors,
name = "") +
scale_fill_manual(values = variant_colors) +
facet_wrap(~UKHSA_region) +
theme(legend.position = "bottom") +
labs(color = "",
title = sgtf_title,
caption = sgtf_caption)
save_plot("variants_england.pdf",
plot,
base_asp = 0.8,
base_height = 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment