Created
April 6, 2020 20:55
This file contains hidden or 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(covid19italy) | |
library(tidyverse) | |
library(scales) | |
library(ggthemes) | |
library(lubridate) | |
library(zoo) | |
update_data() | |
#get regional data | |
iregion <- italy_region %>% | |
arrange(region_name,date) %>% | |
group_by(region_name) %>% | |
mutate(case_change = ifelse(date == min(date),cumulative_cases,cumulative_cases - lag(cumulative_cases)), | |
case_growth = ifelse(date == min(date),0,(cumulative_cases - lag(cumulative_cases))/lag(cumulative_cases)), | |
death_growth = ifelse(date == min(date),0,(death - lag(death))/lag(death)), | |
daily_death = ifelse(date == min(date),death,death - lag(death)), | |
rolling_positives = rollapply(case_change,7,mean,align='right',fill=NA), | |
rolling_deaths = rollapply(daily_death,7,mean,align='right',fill=NA)) %>% | |
ungroup() | |
quarantine_date = as_date('2020-03-08') | |
national_quarantine = as_date('2020-03-09') | |
lombardy <- iregion %>% | |
filter(region_name == 'Lombardia') %>% | |
mutate(quarantine_status = date >= quarantine_date) | |
#plot it | |
lplot <- lombardy %>% | |
filter(!is.na(rolling_positives)) %>% | |
ggplot(aes(x=date,y=rolling_positives))+ | |
geom_line()+ | |
scale_y_continuous(labels = comma)+ | |
scale_x_date()+ | |
theme_tufte()+ | |
ggtitle('Lombardy: COVID-19 rolling 7-day average for new confirmed cases')+ | |
xlab('Date') + | |
ylab('Cases')+ | |
geom_vline(xintercept = quarantine_date,linetype=2,alpha=0.5)+ | |
geom_text(aes(x=quarantine_date, label="\nregional quarantine", y=1000), colour="black", angle=90, text=element_text(size=9)) | |
#southern version | |
mg <- c('Abruzzo','Basilicata','Calabria','Campania','Molise','Puglia','Sicilia') | |
mg_plot <- iregion %>% | |
filter(!is.na(rolling_positives)) %>% | |
filter(region_name %in% mg) %>% | |
ggplot(aes(x=date,y=rolling_positives,col=region_name))+ | |
geom_line()+ | |
scale_y_continuous(labels = comma)+ | |
scale_x_date()+ | |
theme_tufte()+ | |
ggtitle('Southern Italy: COVID-19 rolling 7-day average for new confirmed cases')+ | |
xlab('Date') + | |
ylab('Cases')+ | |
labs(col='Region')+ | |
geom_vline(xintercept = quarantine_date,linetype=2,alpha=0.5)+ | |
geom_text(aes(x=national_quarantine, label="\nnational quarantine", y=100), colour="black", angle=90, text=element_text(size=9)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment