Created
August 18, 2022 09:28
-
-
Save mschnetzer/c71cd74d544f8bfe6f82df3eea8b53fb to your computer and use it in GitHub Desktop.
Inflation-Stream mit Open Data von Statistik Austria
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
librarian::shelf(tidyverse, janitor, ggstream, ggtext, colorspace, MetBrewer, msthemes) | |
rawdata <- read.csv2("https://data.statistik.gv.at/data/OGD_vpi15_VPI_2015_1.csv") | |
coicop <- read.csv2("https://data.statistik.gv.at/data/OGD_vpi15_VPI_2015_1_C-VPI5-0.csv") | |
inflation <- rawdata %>% | |
mutate(datum = ym(str_extract(C.VPIZR.0, "(\\d)+"))) %>% | |
left_join(coicop %>% select(code, name), by = c("C.VPI5.0"="code")) %>% | |
select(datum, Coicop = name, Beitrag = F.VPIEFVJM) %>% | |
drop_na() %>% | |
pivot_wider(names_from = Coicop, values_from = Beitrag) %>% | |
clean_names() | |
plotdat <- inflation %>% | |
mutate(`Wohnen & Energie` = x04_wohnung_wasser_energie + x05_hausrat_instandhaltung_des_hauses, | |
Sonstige = x02_alkoholische_getranke_und_tabak + x03_bekleidung_und_schuhe + | |
x06_gesundheitspflege + x08_nachrichtenubermittlung + | |
x10_erziehung_und_unterricht + x12_verschiedene_waren_dienstleistungen) %>% | |
select(Datum = datum, | |
Inflation = gesamtindex_nach_coicop, | |
Nahrungsmittel = x01_nahrungsmittel_alkoholfr_getranke, | |
`Wohnen & Energie`, | |
Verkehr = x07_verkehr, | |
`Freizeit & Kultur` = x09_freizeit_und_kultur, | |
`Restaurants & Hotels` = x11_restaurants_und_hotels, | |
Sonstige) %>% | |
pivot_longer(cols = -Datum, names_to = "Coicop", values_to = "Beitrag") %>% | |
mutate(Coicop = factor(Coicop, levels = c("Sonstige","Restaurants & Hotels","Freizeit & Kultur","Nahrungsmittel","Wohnen & Energie","Verkehr","Inflation"))) %>% | |
filter(Datum >= "2019-01-01") | |
lastdate <- plotdat %>% slice_max(Datum, n=1) %>% | |
filter(Coicop == "Inflation") | |
firstdate <- plotdat %>% slice_min(Datum, n=1) %>% | |
filter(Coicop == "Inflation") | |
plotdat %>% filter(!Coicop == "Inflation") %>% | |
ggplot(aes(x = Datum, y = Beitrag, group = Coicop, fill = Coicop)) + | |
geom_stream(type = "mirror") + | |
geom_segment(aes(x = Datum + 20, xend = Datum + 20, | |
y = -Beitrag/2 + 0.2, yend = Beitrag/2 - 0.2, fill = NULL), | |
data = lastdate, size = 0.1, color = "gray40", | |
arrow = arrow(ends = "both", length = unit(0.1,"cm"), type = "closed")) + | |
annotate("text", x = lastdate$Datum+30, y = 0, | |
label = glue::glue("Inflationsrate {month(lastdate$Datum, label = T, abbr = F)} {year(lastdate$Datum)}: {lastdate$Beitrag}%"), | |
vjust = 0, family = "Raleway", color = "gray40", size = 2.5) + | |
geom_segment(aes(x = Datum-20, xend = Datum-20, | |
y = -Beitrag/2+0.05, yend = Beitrag/2-0.05, fill = NULL), | |
data = firstdate, size = 0.1, color = "gray40", | |
arrow = arrow(ends = "both", length = unit(0.1,"cm"), type = "closed")) + | |
annotate("text", x = firstdate$Datum-30, y = 0, | |
label = glue::glue("Inflationsrate {month(firstdate$Datum, label = T, abbr = F)} {year(firstdate$Datum)}: {firstdate$Beitrag}%"), | |
vjust = 1, family = "Raleway", color = "gray40", size = 2.5) + | |
annotate("label", x = as.Date("2020-11-01"), y = -4.4, hjust = 0, | |
label = "Inflation in Österreich", family = "Playfair Display", size = 5, | |
label.size = NA) + | |
annotate("text_box", x = as.Date("2020-10-01"), y = -4.4, hjust = 0, vjust = 1, | |
label = "Die Grafik zeigt die Beiträge ausgewählter COICOP-Kategorien zum Verbraucherpreisindex (VPI). Die Werte stellen den Vergleich zum Vorjahresmonat dar.", | |
family = "Raleway", size = 3, color = "gray20", width = unit(5.2, "cm"), | |
box.colour = NA) + | |
annotate("label", x = as.Date("2020-04-01"), y = -4.3, hjust = 0, | |
label = "Daten: Statistik Austria\nGrafik: @matschnetzer", | |
family = "Raleway", size = 2.5, color = "gray20", label.size = NA, fill = "white") + | |
scale_fill_manual(values = c("gray90", darken(met.brewer("Juarez")[-4],.1)), | |
name = "", guide = guide_legend(reverse = TRUE, keywidth = 0.5)) + | |
scale_x_date(date_labels = "%b %y", position = "top", | |
breaks = seq(firstdate$Datum, lastdate$Datum, by="4 months")) + | |
coord_flip(expand = F, xlim = c(firstdate$Datum - 60, lastdate$Datum + 60), | |
ylim = c(-4.5,4.6)) + | |
labs(x=NULL, y=NULL) + | |
theme_ms() + | |
theme(legend.position = c(0.8,0.27), | |
legend.background = element_rect(fill = "white", colour = NA), | |
legend.text = element_text(size = 9, family = "Raleway"), | |
panel.grid.major.x = element_blank(), | |
axis.text.y = element_text(family = "Raleway", color = "gray50", size = 7), | |
axis.text.x = element_blank()) | |
ggsave("inflation.png", width = 6, height = 8, dpi=320) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment