Created
January 1, 2022 17:04
-
-
Save lvegro/6daebe60eb05eeeaa4a4681983ddf64d to your computer and use it in GitHub Desktop.
tassi di crescita ricoveri covid19 per stato vaccinale
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
| require(readr) | |
| require(tidyverse) | |
| require(ggnewscale) | |
| Sys.setlocale(locale="it_IT.UTF-8") | |
| nosignfmt <- function(l){ | |
| return(abs(l)) | |
| } | |
| substrRight <- function(x, n){ | |
| substr(x, nchar(x)-n+1, nchar(x)) | |
| } | |
| v <- read_csv("Downloads/data-vntPP.csv") | |
| long <- v %>% gather(key = "fascia_anagrafica", value = "value", -Date) %>% | |
| mutate(stato_vaccinale = substrRight(fascia_anagrafica,2)) %>% | |
| mutate(fascia_anagrafica = substr(fascia_anagrafica, start = 1, | |
| stop = nchar(fascia_anagrafica)-3)) %>% | |
| mutate(value = if_else(stato_vaccinale == "nv", value, value)) %>% | |
| mutate(Date = as.Date(Date, format="%d/%m/%y")) %>% | |
| mutate(fascia_anagrafica2 = fascia_anagrafica) | |
| wide2 <- long %>% spread(key = c("stato_vaccinale"), value = "value") | |
| reds <- c( | |
| "12_39" = "#FF938A", | |
| "40_59" ="#E57673", | |
| "60_79" ="#C25B5D", | |
| "80+"="#A45A5C" | |
| ) | |
| greens <- c( "12_39" = "#94F4E3", | |
| "40_59" ="#61D2C1", | |
| "60_79" ="#56BAA8", | |
| "80+"="#599D8E") | |
| # --- Rates | |
| # Each value divided by the previous, grouped by stato_vaccinale | |
| filtro_anag <- c( | |
| "12_39", "40-59") | |
| subtit <- case_when(filtro_anag == c("12_39", | |
| "40_59", | |
| "60_79", | |
| "80+") ~ "Tutte le età", | |
| filtro_anag == c("12_39", | |
| "40_59") ~ "Under 60", | |
| filtro_anag == c("60_79", | |
| "80+") ~ "Over 60")[1] | |
| wide2 %>% select(-c(pv, fascia_anagrafica2)) %>% | |
| filter(fascia_anagrafica %in% filtro_anag) %>% | |
| gather(key = "stato_vaccinale", value = "value", -c(Date, fascia_anagrafica)) %>% | |
| group_by(Date, stato_vaccinale) %>% | |
| summarise(value = sum(value)) %>% | |
| arrange(stato_vaccinale, Date) %>% | |
| ungroup() %>% | |
| group_by(stato_vaccinale) %>% | |
| mutate(rate = value/lag(value)) %>% | |
| ggplot(aes(x = Date, y = rate, col = stato_vaccinale, size = rate/3))+ | |
| geom_hline(yintercept = 1, aes(col = "dark grey", lty=2, size=1.5))+ | |
| geom_path(aes(col=stato_vaccinale, size=rate/3),lineend="round", linejoin = "mitre") + | |
| theme(legend.position = "none") + | |
| xlab("Data") + | |
| ylab("")+ | |
| ggthemes::theme_few()+ | |
| theme(text = element_text(size = 22), | |
| panel.grid.major.y = element_line(size = (0.2), colour="grey"), | |
| panel.grid.minor.y = element_line(size=0.2, colour="grey", linetype = "dotted"), | |
| legend.position = "none" | |
| )+ | |
| scale_color_manual(values = c("nv"="#A45A5C", "fv"="#599D8E"))+ | |
| ggtitle("Covid-19 Italia - Tassi di crescita dei ricoveri per stato vaccinale",subtitle = "Under 60")+ | |
| scale_y_continuous(labels = nosignfmt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment