Skip to content

Instantly share code, notes, and snippets.

@seandavi
Created June 25, 2020 15:50
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 seandavi/1dab480e54cdd8452254489fd9df775b to your computer and use it in GitHub Desktop.
Save seandavi/1dab480e54cdd8452254489fd9df775b to your computer and use it in GitHub Desktop.
Countries vying for largest share of new COVID-19 cases
library(sars2pack)
library(dplyr)
library(zoo)
library(cowplot)
library(ggplot2)
y = ecdc_data() %>% dplyr::group_by(iso3c) %>%
add_incidence_column(count_column = 'confirmed') %>%
align_to_baseline(confirmed>50,group_vars = 'iso3c') %>%
dplyr::arrange(date) %>%
dplyr::mutate(inc = zoo::rollmean(inc, 7, na.pad=TRUE)) %>%
dplyr::filter(!is.na(inc) & date<Sys.Date()-2)
p1=ggplot(y[y$iso3c %in% c('USA','BRA','RUS','IND'),], aes(x=index, y=inc, color=iso3c)) +
geom_line() + ggtitle('Countries vying for largest share of new COVID-19 cases per day') +
theme_bw() + ylab('New Cases per Day') + xlab('Days since 50 cases')
p2=ggplot(y[y$iso3c %in% c('USA','BRA','RUS','IND'),], aes(x=index, y=inc/population_2019*100000, color=iso3c)) +
geom_line() + ggtitle('Countries vying for largest share of new COVID-19 cases per day',subtitle = 'Cases/100k population') +
theme_bw() + ylab('New Cases per Day per 100k Population') + xlab('Days since 50 cases')
cowplot::plot_grid(p1,p2,nrow=2)
@anangsowah
Copy link

ecdc_data() %>% dplyr::group_by(iso3c) %>%
add_incidence_column(count_column = 'confirmed') %>%
align_to_baseline(confirmed>50,group_vars = 'iso3c') %>%
dplyr::arrange(date) %>%
dplyr::mutate(inc = zoo::rollmean(inc, 7, na.pad=TRUE)) %>%
dplyr::filter(!is.na(inc) & date<Sys.Date()-2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment