Skip to content

Instantly share code, notes, and snippets.

@johnburnmurdoch
Created March 11, 2020 15:17
Show Gist options
  • Save johnburnmurdoch/34bd7470dca92e470fd5f12a488923ce to your computer and use it in GitHub Desktop.
Save johnburnmurdoch/34bd7470dca92e470fd5f12a488923ce to your computer and use it in GitHub Desktop.
read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv") %>%
gather(date, cases, 5:ncol(.)) %>%
mutate(date = as.Date(date, "%m/%d/%y")) %>%
group_by(country = `Country/Region`, date) %>%
summarise(cases = sum(cases)) %>%
filter(country != "Others" & country != "Mainland China") %>%
bind_rows(
tibble(country = "Republic of Korea", date = as.Date("2020-03-11"), cases = 7755)
) %>%
group_by(country) %>%
mutate(days_since_100 = as.numeric(date-min(date[cases >= 100]))) %>%
ungroup() %>%
filter(is.finite(days_since_100)) %>%
group_by(country) %>%
mutate(new_cases = cases-cases[days_since_100 == 0]) %>%
filter(sum(cases >= 100) >= 5) %>%
filter(cases >= 100) %>%
bind_rows(
tibble(country = "33% daily rise", days_since_100 = 0:18) %>%
mutate(cases = 100*1.33^days_since_100)
) %>%
ungroup() %>%
mutate(
country = country %>% str_replace_all("( SAR)|( \\(.+)|(Republic of )", "")
) %>%
# filter(days_since_100 <= 10) %>%
ggplot(aes(days_since_100, cases, col = country)) +
geom_hline(yintercept = 100) +
geom_vline(xintercept = 0) +
geom_line(size = 0.8) +
geom_point(pch = 21, size = 1) +
scale_y_log10(expand = expand_scale(add = c(0,0.1)), breaks=c(100, 200, 500, 1000, 2000, 5000, 10000)) +
# scale_y_continuous(expand = expand_scale(add = c(0,100))) +
scale_x_continuous(expand = expand_scale(add = c(0,1))) +
theme_minimal() +
theme(
panel.grid.minor = element_blank(),
legend.position = "none",
plot.margin = margin(3,15,3,3,"mm")
) +
coord_cartesian(clip = "off") +
scale_colour_manual(values = c("UK" = "#ce3140", "US" = "#EB5E8D", "Italy" = "black", "France" = "#c2b7af", "Germany" = "#c2b7af", "Hong Kong" = "#1E8FCC", "Iran" = "#9dbf57", "Japan" = "#208fce", "Singapore" = "#1E8FCC", "Korea" = "#208fce", "Belgium" = "#c2b7af", "Netherlands" = "#c2b7af", "Norway" = "#c2b7af", "Spain" = "#c2b7af", "Sweden" = "#c2b7af", "Switzerland" = "#c2b7af", "33% daily rise" = "#D9CCC3")) +
geom_shadowtext(aes(label = paste0(" ",country)), hjust=0, vjust = 0, data = . %>% group_by(country) %>% top_n(1, days_since_100), bg.color = "white") +
labs(x = "Number of days since 100th case", y = "", subtitle = "Total number of cases")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment