Created
May 6, 2020 10:39
-
-
Save thoughtfulbloke/9923becafed94b8fcc877e834bd3a923 to your computer and use it in GitHub Desktop.
code for NZ vs UK to show similarity in early progression
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(dplyr) | |
library(lubridate) | |
library(ggplot2) | |
EUcdc <- read.csv("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv", | |
stringsAsFactors = FALSE, fileEncoding = "UTF-8-BOM") | |
# NZ level 4 lockdown 26 March | |
#Boris Handshakes 3 March, | |
EUcdc %>% | |
filter(countriesAndTerritories %in% c("United_Kingdom", "New_Zealand")) %>% | |
mutate(ReportDate = dmy(dateRep)) %>% | |
arrange(countriesAndTerritories, ReportDate) %>% | |
group_by(countriesAndTerritories) %>% | |
mutate(total_cases = cumsum(cases)) %>% | |
filter(total_cases > 19) %>% | |
mutate(days = as.integer(difftime(ReportDate, min(ReportDate), units="day"))) %>% | |
slice(1:21) %>% | |
ungroup() %>% | |
select(countriesAndTerritories, days, ReportDate, total_cases) %>% | |
ggplot(aes(x=days, y=total_cases, colour=countriesAndTerritories)) + | |
geom_line() + theme_minimal() + | |
scale_colour_manual(name="Country", values=c("#377eb8","#ff7f00")) + | |
annotate("segment", x=2, xend=2, y=40, yend=4000, | |
colour="#ff7f00", linetype=2) + | |
annotate("segment", x=8, xend=8, y=262, yend=4000, | |
colour="#377eb8", linetype=2) + | |
annotate("text", x=2.9, y=4000, angle=90, colour="#ff7f00", hjust=1, | |
label="Boris shaking hands with covid-19 patients") + | |
annotate("text", x=8.9, y=4000, angle=90, colour="#377eb8", hjust=1, | |
label="New Zealand goes to level 4 lockdown") + | |
xlab("Days since 20th case") + ylab("Total confirmed cases")+ | |
labs(title="Covid-19 timeline over 3 weeks after the 20th case", | |
caption="Data:European Centre for Disease Control and Prevention") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment