knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(covdata) library(tidyverse)
covnat_weekly
## Libraries for the graphs library(ggrepel) ## Convenince "Not in" operator "%nin%" <- function(x, y) { return( !(x %in% y) ) } ## Countries to highlight focus_on <- covnat_weekly %>% filter(cu_cases > 99, pop > 1e7) %>% mutate(rate = cu_cases / pop) %>% group_by(iso3) %>% summarize(mean_rate = mean(rate, na.rm = TRUE)) %>% slice_max(n = 20, order_by = mean_rate) %>% pull(iso3) ## Colors cgroup_cols <- c("#195F90FF", "#D76500FF", "#238023FF", "#AB1F20FF", "#7747A3FF", "#70453CFF", "#D73EA8FF", "#666666FF", "#96971BFF", "#1298A6FF", "#6F9BD6FF", "#FF952DFF", "#195F90FF", "#D76500FF", "#238023FF", "#70453CFF", "#D73EA8FF", "#666666FF", "#96971BFF", "#1298A6FF", "gray70") covnat_weekly %>% filter(cu_cases > 99, pop > 1e7) %>% mutate(rate = cu_cases / pop) %>% mutate(days_elapsed = date - min(date), end_label = ifelse(date == max(date), cname, NA), end_label = recode(end_label, `United States` = "USA", `Bolivia, Plurinational State of` = "Bolivia", `Russian Federation` = "Russia", `Dominican Republic` = "Dominican Rep.", `Iran, Islamic Republic of` = "Iran", `Korea, Republic of` = "South Korea", `United Kingdom` = "UK"), cname = recode(cname, `United States` = "USA", `Iran, Islamic Republic of` = "Iran", `Korea, Republic of` = "South Korea", `United Kingdom` = "UK"), end_label = case_when(iso3 %in% focus_on ~ end_label, TRUE ~ NA_character_), cgroup = case_when(iso3 %in% focus_on ~ iso3, TRUE ~ "ZZOTHER")) %>% ggplot(mapping = aes(x = days_elapsed, y = cu_cases / pop, color = cgroup, label = end_label, group = cname)) + geom_line(size = 0.5) + geom_text_repel(nudge_x = 0.75, segment.color = NA) + guides(color = FALSE) + scale_color_manual(values = cgroup_cols) + labs(x = "Days Since 100th Confirmed Case", y = "Cumulative reported Cases per capita", title = "Cumulative Reported Cases of COVID-19 per capita", subtitle = paste("Selected Countries with >1m population. ECDC data as of", format(max(covnat_weekly$date), "%A, %B %e, %Y")), caption = "Kieran Healy @kjhealy / Data: https://www.ecdc.europa.eu/") + theme_minimal()
covnat_weekly %>% filter(iso3 %in% focus_on) %>% ggplot(mapping = aes(x = date, y = (deaths/pop)*1e6)) + geom_line(size = 0.5) + # scale_y_continuous(labels = scales::comma_format(accuracy = 1)) + facet_wrap(~ cname) + labs(x = "Date", y = "Deaths per Million Population", title = "Deaths from COVID-19, Selected Countries", subtitle = paste("ECDC weekly data as of", format(max(covnat_weekly$date), "%A, %B %e, %Y")), caption = "Kieran Healy @kjhealy / Data: https://www.ecdc.europa.eu/") + theme_minimal()
Note the effects of reporting issues in various countries.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.