Last active
November 9, 2021 11:40
-
-
Save lvegro/9eb158e28df8a33146f4f6f0796508fd to your computer and use it in GitHub Desktop.
Tempo trascorso dalle vaccinazioni - ITA
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(tidyverse) | |
| library(readr) | |
| library(ggthemes) | |
| library(rjson) | |
| last_update <- fromJSON(file = "https://raw.githubusercontent.com/italia/covid19-opendata-vaccini/master/dati/last-update-dataset.json") | |
| last_update <- substr(last_update[[1]], 1, 19) | |
| last_update <- gsub("T", " ", last_update) | |
| last_update <- as.POSIXct(last_update) + 2 * 60 * 60 | |
| v <- read_csv("https://raw.githubusercontent.com/italia/covid19-opendata-vaccini/master/dati/somministrazioni-vaccini-latest.csv") | |
| s <- v %>% group_by(data_somministrazione, fascia_anagrafica) %>% | |
| mutate(dose_finale = seconda_dose + pregressa_infezione + ifelse(fornitore=="Janssen", prima_dose,0)) %>% | |
| summarise(dosi = sum(dose_finale)) %>% | |
| mutate(diffdays = as.integer(Sys.Date() - data_somministrazione)) %>% | |
| filter(dosi > 0) %>% | |
| mutate( | |
| tempo_dal_vaccino = case_when( | |
| diffdays >= 180 ~ "Più di 6 mesi", | |
| diffdays < 180 & | |
| diffdays >= 90 ~ "Tra 3 e 6 mesi", | |
| diffdays < 90 ~ "< 3 mesi" | |
| ) | |
| ) %>% | |
| group_by(fascia_anagrafica, tempo_dal_vaccino) %>% | |
| summarise(dosi = sum(dosi)) | |
| s$tempo_dal_vaccino <- | |
| factor(s$tempo_dal_vaccino, | |
| levels = c("< 3 mesi", "Tra 3 e 6 mesi", "Più di 6 mesi")) | |
| s %>% ggplot(mapping = aes(x = fascia_anagrafica, y = dosi, fill = tempo_dal_vaccino)) + | |
| geom_col(position = "fill") + | |
| scale_fill_brewer(palette = "Blues") + | |
| scale_y_continuous(labels = scales::percent) + | |
| ggthemes::theme_few() + | |
| xlab("Fascia Anagrafica") + | |
| ylab("% vaccinati") + | |
| labs(title = "Tempo trascorso da completamento ciclo vaccinale con doppia dose", | |
| subtitle = "Sono escluse le persone che hanno ricevuto una sola dose (J&J o pregressa infezione)", | |
| caption = paste("Fonte dati: Covid-19 Opendata Vaccini | Data aggiornamento:", last_update), | |
| fill = "Tempo trascorso dal vaccino") + | |
| theme(legend.position = "bottom") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment