Last active
November 3, 2021 17:17
-
-
Save mschnetzer/7525dd047a3673d49465657fa5705ebd to your computer and use it in GitHub Desktop.
Covid 7-Tage-Inzidenz nach Altersgruppen (https://twitter.com/matschnetzer/status/1455938384925450240?s=20)
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(lubridate) | |
library(msthemes) | |
library(patchwork) | |
# Get Covid data by age here: https://www.data.gv.at/katalog/dataset/3765ed62-0f9d-49ad-83b0-1405ed833108 | |
# And vaccination data here: https://www.ages.at/themen/krankheitserreger/coronavirus/ | |
cov <- read_csv2("CovidFaelle_Altersgruppe.csv") %>% | |
mutate(Time = as.Date(Time, "%d.%m.%Y")) | |
cdat <- cov %>% filter(Bundesland == "Österreich") %>% | |
group_by(Time, Altersgruppe, AltersgruppeID) %>% | |
summarise(fall = sum(Anzahl), ew = sum(AnzEinwohner)) %>% | |
group_by(Altersgruppe) %>% | |
mutate(inzidenz = (fall-lag(fall,7))/ew*1e5) %>% | |
drop_na() | |
impf <- bind_rows(read_csv2("Inzidenz_Impfstatus_12bis17Jahre.csv", col_names=F) %>% | |
mutate(Alter = "12-17"), | |
read_csv2("Inzidenz_Impfstatus_18bis59Jahre.csv", col_names=F) %>% | |
mutate(Alter = "18-59"), | |
read_csv2("Inzidenz_Impfstatus_60plus.csv", col_names=F) %>% | |
mutate(Alter = "60+")) %>% | |
select(Time = X1, Geimpft = X2, Ungeimpft = X3, Alter) %>% | |
mutate(Time = as.Date(Time, "%d.%m.%Y"), | |
Alter = factor(Alter, levels = c("60+","18-59","12-17")), | |
across(c(Geimpft,Ungeimpft), ~str_replace_all(., ",", "."))) %>% | |
drop_na() %>% | |
pivot_longer(cols = c(Geimpft, Ungeimpft), names_to = "Impfstatus", values_to = "Inzidenz", values_transform = list(Inzidenz = as.numeric)) | |
full <- cdat %>% | |
ggplot(aes(x = Time, y = reorder(Altersgruppe, AltersgruppeID), fill = inzidenz)) + | |
geom_tile() + | |
scale_y_discrete(expand = c(0,0)) + | |
scale_x_date(date_breaks = "2 months", expand = c(0,0), date_labels = "%b %y") + | |
geom_rect(aes(xmin= as.Date("2021-08-01"), xmax = today()-1, ymin=-Inf, ymax=Inf), color = "black", fill = NA, size = 0.3) + | |
# geom_rect(aes(xmin= as.Date("2020-07-01"), xmax = max(cdat$Time)-years(1), ymin=-Inf, ymax=Inf), color = "black", fill = NA, size = 0.1) + | |
scale_fill_viridis_c(option = "magma", direction = -1, limits = c(0,1200), | |
guide = guide_colorbar(title = "", | |
title.vjust = 0.5, barwidth = 15, | |
barheight = 0.5, ticks = F, | |
label.theme = element_text(size = 9, family = "Raleway"))) + | |
labs(x="", y="") | |
short <- cdat %>% | |
filter(Time >= "2021-08-01") %>% | |
ggplot(aes(x = Time, y = reorder(Altersgruppe, AltersgruppeID), fill = inzidenz)) + | |
geom_tile(size = 0.15, color = "white") + | |
scale_y_discrete(expand = c(0,0)) + | |
scale_x_date(date_breaks = "1 month", expand = c(0,0), date_labels = "%d. %b") + | |
scale_fill_viridis_c(option = "magma", direction = -1, limits = c(0,1200), | |
guide = guide_none()) + | |
labs(x="", y="") | |
vacc <- impf %>% | |
filter(Time >= "2021-08-01") %>% | |
ggplot(aes(x = Time, y = Impfstatus, fill = Inzidenz)) + | |
geom_tile(size = 0.15, color = "white") + | |
scale_y_discrete(expand = c(0,0)) + | |
scale_x_date(date_breaks = "1 month", expand = c(0,0), date_labels = "%d. %b") + | |
scale_fill_viridis_c(option = "magma", direction = -1, limits = c(0,1200), | |
guide = guide_none()) + | |
labs(x="", y="") + | |
facet_wrap(~Alter, nrow = 3, strip.position = "left") | |
final <- full / ( short + vacc) + | |
plot_layout(guides = "collect", widths = c(3,1)) + | |
plot_annotation(title = "Entwicklung 4. Corona-Welle in Österreich", | |
subtitle = "7-Tage-Inzidenz nach Altersgruppen und Impfstatus", | |
caption = "Daten: AGES/EMS. Grafik: @matschnetzer") & | |
theme_ms(alttf = T) + | |
theme(axis.ticks.x = element_line(size = 0.1), | |
strip.background = element_rect(fill = "grey97", size = 0), | |
strip.text = element_text(size = 7, hjust = 0.5, margin = margin(3,3,3,3)), | |
axis.text.x = element_text(size = 7, hjust = 0.5), | |
axis.text.y = element_text(size = 7, vjust = 0.5), | |
legend.position = "bottom") | |
ggsave(final, filename = "covidheatlarge.png", dpi = 320, width = 8, height = 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment