Created
December 20, 2020 03:11
-
-
Save theosanderson/9bb358c04dd46cd50d58c9e4c06561ed to your computer and use it in GitHub Desktop.
Code for N501Y plot
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(tidyverse) | |
library(gganimate) | |
library(lubridate) | |
data <- | |
read_csv("D:/cases_anim/cog_metadata_microreact_public.csv.txt") | |
data$sample_date = ymd(data$sample_date) | |
library(sp) | |
library('sf') | |
ltlas <- | |
read_sf( | |
"D:/cases_anim/Counties_and_Unitary_Authorities__December_2017__Boundaries_in_the_UK__WGS84_-shp/Counties_and_Unitary_Authorities__December_2017__Boundaries_in_the_UK__WGS84_.shp" | |
) | |
data <- filter(data, !is.na(latitude)) | |
pts <- | |
st_as_sf(tibble(data$latitude, data$longitude), | |
coords = c(2, 1), | |
crs = 4326) | |
ltlas <- st_transform(ltlas, crs = 3857) | |
pts <- st_transform(pts, crs = 3857) | |
a = st_join(pts, ltlas) | |
data$ltla = a$ctyua17nm | |
agg = data %>% filter(n501y == "Y") %>% group_by(ltla) %>% summarise(num = | |
n()) %>% arrange(-num) | |
ggplot( | |
data %>% filter(ltla %in% agg$ltla[1:10], epi_week < 50, ltla != "NA"), | |
aes(x = epi_week, fill = n501y) | |
) + geom_bar(position = "fill") + facet_wrap( ~ ltla, scales = "free_y") + | |
theme_bw() + scale_fill_manual(values = c("darkgray", "green", "darkblue", "darkred")) + | |
labs(fill = "N501Y", y = "Relative frequency") + scale_y_continuous(labels = scales::percent) | |
ggsave("graph.pdf", width = 6, height = 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment