Created
March 4, 2020 14:51
-
-
Save matteodefelice/c9dd063805298a1236d25faf1e9e7be7 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) | |
df <- read_csv("ItalianCovidData/Daily Covis19 Italian Data Cumulative") %>% | |
select(1:5) %>% | |
gather(type, value, -Date, -Region) %>% | |
group_by(Date, Region) | |
total <- df %>% | |
dplyr::filter(Date == max(df$Date)) %>% | |
group_by( | |
Region | |
) %>% | |
summarise( | |
total = sum(value) | |
) %>% | |
arrange(desc(total)) | |
df_sel <- df %>% | |
ungroup() %>% | |
mutate(region_label = as.factor(Region) %>% | |
fct_other(keep = c("Lombardia", "Emilia Romagna", "Veneto"), other_level = "resto d'Italia") %>% | |
fct_relevel("resto d'Italia", "Veneto", "Emilia Romagna", "Lombardia")) %>% | |
ungroup() %>% | |
group_by(Date, Regione = region_label, type) %>% | |
summarise(value = sum(value)) %>% | |
mutate( | |
type_italian = case_when( | |
type == "Home Isolation" ~ "Isolamento domestico", | |
type == "Hospitalised" ~ "In ospedale (esclusi T.I.)", | |
type == "In ICU" ~ "In terapia intensiva (T.I.)" | |
) | |
) | |
g <- ggplot(df_sel, aes(x = Date, y = value, fill = Regione)) + | |
geom_bar(stat = "identity") + | |
facet_wrap(~type_italian, scales = "free", nrow = 1) + | |
theme_light() + | |
scale_fill_brewer(palette = "Set2") + | |
labs( | |
x = "", y = "Casi", title = "Italia Covid19", | |
subtitle = "Dati Protezione Civile aggiornati al 3 Marzo 2020 ore 18:00", | |
caption = "Fonte dati: https://github.com/DavideMagno/ItalianCovidData" | |
) + | |
theme( | |
strip.background = element_rect(fill = "grey30"), | |
axis.text.x = element_text(angle = 45, hjust = 1) | |
) | |
ggsave("situazione_italiana.png", width = 8, height = 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment