Last active
July 28, 2022 18:10
-
-
Save mschnetzer/d359eeedd91d91da4d58e96c18cac476 to your computer and use it in GitHub Desktop.
Inflationsentwicklung nach ausgewählten COICOP-Kategorien (https://twitter.com/matschnetzer/status/1552716619482374151)
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
| librarian::shelf(tidyverse, msthemes, janitor, lubridate, ggstream, MetBrewer, ggtext) | |
| # Data from statcube.at | |
| raw <- readxl::read_xlsx("table_2022-07-27_23-59-52.xlsx", na = "-", sheet = "Data Sheet 0", range = "B11:AU57") | |
| inflation <- raw %>% | |
| clean_names() %>% | |
| mutate(Wohnen = x04_wohnung_wasser_energie - x04_5_aufwand_fur_energie) %>% | |
| select("Datum" = "x1", | |
| "Inflation" = "gesamtindex_nach_coicop", | |
| "Nahrungsmittel" = "x01_nahrungsmittel_alkoholfr_getranke", | |
| "Alkhol_Tabak" = "x02_alkoholische_getranke_und_tabak", | |
| "Bekleidung_Schuhe" = "x03_bekleidung_und_schuhe", | |
| "Wohnen", | |
| "Energie" = "x04_5_aufwand_fur_energie", | |
| "Haushalt" = "x05_hausrat_instandhaltung_des_hauses", | |
| "Gesundheit" = "x06_gesundheitspflege", | |
| "Verkehr" = "x07_verkehr", | |
| "Nachrichtenübermittlung" = "x08_nachrichtenubermittlung", | |
| "Freizeit_Kultur" = "x09_freizeit_und_kultur", | |
| "Erziehung_Unterricht" = "x10_erziehung_und_unterricht", | |
| "Restaurants & Hotels" = "x11_restaurants_und_hotels", | |
| "Dienstleistungen" = "x12_verschiedene_waren_dienstleistungen") %>% | |
| drop_na() %>% | |
| mutate(Datum = str_replace_all(Datum, "Jän", "Jan"), | |
| Datum = dmy(paste("01", Datum))) | |
| subdata <- inflation %>% | |
| mutate(Sonstige = Freizeit_Kultur + Dienstleistungen + Gesundheit + Alkhol_Tabak + Bekleidung_Schuhe + | |
| Erziehung_Unterricht + Nachrichtenübermittlung, | |
| `Wohnen & Haushalt` = Wohnen + Haushalt) %>% | |
| select(Datum, Verkehr, Nahrungsmittel, Energie, `Restaurants & Hotels`, `Wohnen & Haushalt`, Sonstige) %>% | |
| pivot_longer(cols = -Datum, names_to = "Coicop", values_to = "Beitrag") %>% | |
| mutate(Coicop = factor(Coicop, levels = c("Sonstige","Restaurants & Hotels","Nahrungsmittel","Wohnen & Haushalt","Energie","Verkehr"))) | |
| subdata %>% | |
| ggplot(aes(x=Datum, y=Beitrag, group=Coicop, fill = Coicop)) + | |
| geom_stream(type = "mirror") + | |
| geom_segment(aes(x = as.Date("2022-06-20"), xend = as.Date("2022-06-20"), y = -4.1, yend = 4.1), | |
| size = 0.1, color = "gray60", | |
| arrow = arrow(ends = "both", length = unit(0.1,"cm"), type = "closed")) + | |
| annotate("text", x = as.Date("2022-07-01"), y = 0, | |
| label = "Inflationsrate Juni 2022: 8.6%", | |
| vjust = 0, family = "Raleway", color = "gray30", size = 2.5) + | |
| geom_segment(aes(x = as.Date("2018-12-10"), xend = as.Date("2018-12-10"), y = -1.8/2, yend = 1.8/2), | |
| size = 0.1, color = "gray60", | |
| arrow = arrow(ends = "both", length = unit(0.1,"cm"), type = "closed")) + | |
| annotate("text", x = as.Date("2018-11-20"), y = 0, | |
| label = "Inflationsrate Jänner 2019: 1,8%", | |
| vjust = 1, family = "Raleway", color = "gray30", 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, "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(as.Date("2019-01-01"), as.Date("2022-05-01"), by="4 months")) + | |
| coord_flip(expand = F, xlim = c(as.Date("2018-10-01"), as.Date("2022-08-01")), 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