Created
May 4, 2020 20:39
-
-
Save randallhelms/34ee23fce3650738f2f6c11a6bd1a5af to your computer and use it in GitHub Desktop.
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
library(tidyverse) | |
library(scales) | |
library(ggthemes) | |
library(lubridate) | |
library(zoo) | |
library(covid19us) | |
library(datasets) | |
tsa <- c('NY','CT','NJ') | |
states <- tibble(state_name = state.name, | |
state = state.abb) | |
us <- get_states_daily() %>% | |
mutate(grouping = ifelse(state %in% tsa,'NY Tri-State Area','Rest of the US')) %>% | |
arrange(state,date) %>% | |
mutate(pct_positive = positive_increase / total_test_results_increase) %>% | |
group_by(state) %>% | |
mutate(rolling_positives = rollapply(positive_increase,7,mean,align='right',fill=NA), | |
rolling_deaths = rollapply(death_increase,7,mean,align='right',fill=NA), | |
rolling_pct_positive = rollapply(pct_positive,7,mean,align='right',fill=NA), | |
rolling_tests = rollapply(total_test_results_increase,7,mean,align='right',fill=NA)) %>% | |
left_join(states,by='state') %>% | |
select(date,state,state_name,everything()) | |
us2 <- us %>% | |
group_by(grouping,date) %>% | |
summarize(death_increase = sum(death_increase,na.rm=TRUE)) %>% | |
ungroup() %>% | |
arrange(grouping,date) %>% | |
group_by(grouping) %>% | |
mutate(rolling_deaths = rollapply(death_increase,7,mean,align='right',fill=NA)) %>% | |
filter(date >= '2020-03-01') | |
us2_plot <- us2 %>% | |
ggplot(aes(x=date,y=rolling_deaths,col=grouping))+ | |
geom_line()+ | |
scale_y_continuous(labels = comma)+ | |
scale_x_date()+ | |
theme_tufte()+ | |
ggtitle('US rolling 7-day average for confirmed Covid-19 deaths, New York Tri-State Area vs Rest of the USA')+ | |
xlab('Date') + | |
ylab('Rolling 7-day average of deaths')+ | |
labs(col='Grouping') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment