Skip to content

Instantly share code, notes, and snippets.

@RandomCriticalAnalysis
Forked from gorkang/plot-corona.R
Created March 11, 2020 14:54
Show Gist options
  • Save RandomCriticalAnalysis/5f85e8ad437c27c06ff0835646e356d3 to your computer and use it in GitHub Desktop.
Save RandomCriticalAnalysis/5f85e8ad437c27c06ff0835646e356d3 to your computer and use it in GitHub Desktop.
# 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