Last active
March 11, 2020 14:54
-
-
Save gorkang/922d85c8a677d8fa98a0b2b9812a560d to your computer and use it in GitHub Desktop.
COVID plot adapted from https://github.com/JonMinton/COVID-19
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
# FROM: https://github.com/JonMinton/COVID-19 | |
DF = tidied_data %>% | |
filter(type == "confirmed") %>% | |
mutate( | |
higher = case_when( | |
higher == "Iran (Islamic Republic of)" ~ "Iran", | |
higher == "Hong Kong SAR" ~ "Hong Kong", | |
higher == "Republic of Korea" ~ "South Korea", | |
TRUE ~ higher | |
) | |
) %>% | |
group_by(higher, date) %>% | |
summarise(n = sum(n)) %>% | |
ungroup() %>% | |
group_by(higher) %>% | |
arrange(date) %>% | |
filter(n >= 100) %>% | |
mutate(first_date = date[1]) %>% | |
mutate(days_since_first = date - first_date) %>% | |
mutate(max_days_since_first = max(days_since_first)) %>% | |
ungroup() %>% | |
mutate(country = fct_reorder(higher, desc(max_days_since_first))) %>% | |
filter(country != "Others") %>% | |
# Create label in the last day for each country | |
group_by(country) %>% | |
mutate( | |
name_end = | |
case_when( | |
n == max(n) ~ paste0(as.character(country), " - ", days_since_first, " days"), | |
TRUE ~ "" | |
) | |
) | |
DF_names <- DF %>% | |
# group_by(country) %>% | |
distinct(country) %>% | |
pull(country) | |
# PLOT -------------------------------------------------------------------- | |
plot1 = DF %>% | |
ggplot(aes(x = days_since_first, y = n, color = country)) + | |
geom_line() + | |
ggrepel::geom_label_repel(aes(label = name_end), show.legend = FALSE, segment.color = "grey", segment.size = .3) + #, segment.linetype = 5 | |
scale_y_log10( | |
breaks = scales::trans_breaks("log10", function(x) 10^x), | |
labels = scales::trans_format("log10", scales::math_format(10^.x))) + | |
labs( | |
title = "Confirmed cases after first 100 cases", | |
subtitle = "Arranged by number of days since 100 or more cases", | |
x = "Days after 100 confirmed cases", | |
y = "Confirmed cases (log scale)", | |
caption = "Source: Johns Hopkins CSSE" | |
) + | |
theme_minimal() + | |
theme(legend.position = "none") | |
ggsave("figures/days_since_100.png", plot1, height = 20, width = 20, units = "cm", dpi = 300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment