Created
March 15, 2020 20:39
-
-
Save acoppock/0c63a2db2dca389fcf329010346f6dd6 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
rm(list = ls()) | |
library(tidyverse) | |
library(ggrepel) | |
covid <- | |
read_csv(file = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv") | |
covid <- | |
covid %>% filter(`Country/Region` != "Cruise Ship") | |
covid_long <- | |
covid %>% | |
pivot_longer(names_to = "date", | |
values_to = "cases", | |
cols = ends_with("20")) %>% | |
mutate(date = as.Date(date, "%m/%d/%y")) %>% | |
group_by(date, `Country/Region`) %>% | |
summarise(cases = sum(cases)) | |
covid_long <- | |
covid_long %>% | |
group_by(`Country/Region`) %>% | |
mutate(seen_100_cases = max(cases) > 100) %>% | |
filter(seen_100_cases) %>% | |
mutate(dayof100 = min(date[cases > 100]), | |
days_since_100 = date - dayof100) %>% | |
filter(days_since_100 > 0) | |
label_df <- | |
covid_long %>% | |
group_by(`Country/Region`) %>% | |
arrange(-days_since_100) %>% | |
slice(1) %>% | |
filter(days_since_100 > 5) | |
thirty_three <- function(x) | |
100 * (4 / 3) ^ x | |
line_df <- | |
tibble(days_since_100 = 1:50, | |
cases = thirty_three(days_since_100)) | |
g <- | |
ggplot(label_df, aes(days_since_100, cases, group = `Country/Region`)) + | |
geom_text_repel(aes(label = `Country/Region`)) + | |
geom_point() + | |
geom_line(alpha = 0.25, data = covid_long) + | |
geom_line(alpha = 0.25, | |
linetype = "dashed", | |
aes(group = NULL), | |
data = line_df) + | |
scale_y_log10(labels = comma) + | |
annotate("text", 30, thirty_three(30), label = "33% daily increase") + | |
theme_bw() + | |
coord_cartesian(ylim = c(100, 1000000)) + | |
labs( | |
y = "Confirmed cases", | |
x = "Days since 100th case reported", | |
caption = "Data: https://github.com/CSSEGISandData/COVID-19 | |
Code: ", | |
title = "Cumulative cases since 100th case reported", | |
subtitle = "Graph design inspired by @jburnmurdoch | |
https://www.ft.com/content/a26fbf7e-48f8-11ea-aeb3-955839e06441" | |
) | |
ggsave( | |
filename = "covid_graph.pdf", | |
plot = g, | |
width = 6.5, | |
height = 4.5 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated link : https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv