Skip to content

Instantly share code, notes, and snippets.

@webbedfeet
Created March 21, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webbedfeet/ad4a7d7fd6095af66d6da1adb0c19a3c to your computer and use it in GitHub Desktop.
Save webbedfeet/ad4a7d7fd6095af66d6da1adb0c19a3c to your computer and use it in GitHub Desktop.
Code to create COVID-19 attributed death trajectories by country using JHU data
# remotes::install_github('ramikrispin/coronavirus')
library(coronavirus)
update_datasets()
pacman::p_load(char=c('tidyverse','janitor', 'ggrepel'))
deaths <- coronavirus %>%
clean_names() %>%
filter(type=='death') %>%
group_by(country_region, date) %>%
summarise(cases = sum(cases)) %>%
ungroup() %>%
group_by(country_region) %>%
arrange(date) %>%
mutate(cum_cases = cumsum(cases)) %>%
ungroup() %>%
as_tibble()
top_ten <- deaths %>%
filter(date==max(date)) %>%
top_n(10, cum_cases)
deaths_top10 <-
deaths %>%
filter(country_region %in% top_ten$country_region) %>%
group_by(country_region) %>%
filter(cum_cases >= 10) %>%
mutate(days = as.numeric(date - min(date))) %>%
ungroup()
ggplot(deaths_top10, aes(x = days, y = cum_cases)) +
geom_label_repel(data = deaths_top10 %>%
filter(country_region %in% top_ten$country_region) %>%
group_by(country_region) %>%
filter(days == max(days)) %>%
ungroup(),
aes(color = country_region, label = country_region),
hjust = 1, show.legend=F)+
geom_point(data = deaths_top10 %>%
filter(country_region %in% top_ten$country_region) %>%
group_by(country_region) %>%
filter(days == max(days)) %>%
ungroup(),
aes(color = country_region, size=cum_cases),
show.legend=F)+
geom_line(aes(color = country_region), show.legend = F)+
scale_y_log10('Cumulative deaths')+
labs(x = 'Days since 10th death')+
theme_classic()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment