Created
January 24, 2024 10:16
-
-
Save mschnetzer/c508ed38cbb5b3a049569446379f0506 to your computer and use it in GitHub Desktop.
Grafiken zum Tag der Elementarpädagogik (https://x.com/matschnetzer/status/1750075544983449947?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
# GRAFIK: Anteil Kinder mit Mittagessen in der Betreuungseinrichtung | |
library(tidyverse) | |
library(readODS) | |
library(sf) | |
library(ggtext) | |
library(patchwork) | |
bez <- geojsonsf::geojson_sf("https://raw.githubusercontent.com/ginseng666/GeoJSON-TopoJSON-Austria/master/2021/simplified-99.9/bezirke_999_geo.json") | |
temp.file <- paste0(tempfile(),".ods") | |
download.file("https://www.statistik.at/fileadmin/pages/318/5_KTH_Regionaldaten_2022_23_aktualisiert.ods", | |
temp.file, mode = "wb") | |
raw <- read_ods(temp.file, | |
sheet = "Tabelle2", range = "A7:I132", col_names = F) |> | |
select("bezirk" = ...1, "mittag" = ...8) |> | |
mutate(bezirk = str_replace_all(bezirk, c(" \\(Stadt\\)" = "\\(Stadt\\)", | |
" \\(Land\\)" = "\\(Land\\)")), | |
bezirk = case_match(bezirk, | |
"Dornbirn3" ~ "Dornbirn", | |
"Braunau am Inn" ~ "Braunau", | |
"Ried im Innkreis" ~ "Ried", | |
"Kirchdorf an der Krems" ~ "Kirchdorf", | |
"Villach(Stadt)" ~ "Villach Stadt", | |
"Klagenfurt(Stadt)" ~ "Klagenfurt Stadt", | |
"Steyr(Stadt)" ~ "Stadt Steyr", | |
"Wels(Stadt)" ~ "Stadt Wels", | |
"Linz(Stadt)" ~ "Stadt Linz", | |
"Wien" ~ "Wien(Stadt)", | |
.default = bezirk)) | |
findat <- bez |> left_join(raw, by = c("name" = "bezirk")) |> | |
drop_na() |> | |
mutate(anteil = cut(mittag, breaks = seq(0,100,20), | |
labels = glue::glue(">{seq(0,80,20)} bis {seq(20,100,20)}%"))) | |
blmap <- bez |> mutate(bl = str_extract(iso, "^\\d")) |> | |
summarise(geometry = st_union(geometry), .by = bl) | |
p1 <- findat |> | |
ggplot() + | |
geom_sf(aes(fill = anteil), linewidth = 0.1, color = "gray90") + | |
geom_sf(data = blmap, fill = "transparent", linewidth = 0.2, color = "black") + | |
annotate("richtext", x = 9.52, y = 49.1, fill = NA, label.colour = NA, | |
label = "<span style='font-size:26px;font-family:\"Playfair Display\";'>Und, habt's scho Mittag'gessen?</span><br><br>Anteil der Kinder<br>mit <span style='color:#bf4f51;'>Mittagessen</span> in<br>Kindertagesstätten, 2022/23<br><br><span style='font-size:10px;'>Quelle: Statistik Austria · Grafik: @matschnetzer</span>", | |
size = 4, hjust = 0, vjust = 1, family = "Roboto Condensed", lineheight = 1.1) + | |
scale_fill_manual(values = MetBrewer::met.brewer("Tam", direction = -1)[c(1,3,4,6,8)], | |
guide = guide_legend(nrow = 1, label.position = "bottom", | |
keywidth = 4, keyheight = 0.6)) + | |
coord_sf(ylim = c(46.3, 49)) + | |
theme_minimal(base_family = "Roboto Condensed", base_size = 10) + | |
theme(legend.position = c(0.5, 0), | |
legend.title = element_blank(), | |
axis.title = element_blank(), | |
axis.text = element_blank(), | |
panel.grid = element_blank()) | |
p2 <- findat |> slice_max(mittag, n = 5) |> | |
mutate(name = fct_reorder(name, mittag)) |> | |
ggplot(aes(x = name, y = mittag, color = anteil)) + | |
geom_point(size = 2) + | |
geom_segment(aes(xend = name, yend = 0), linewidth = 1.5) + | |
geom_text(y = 0, aes(label = glue::glue("{name}: {round(mittag,0)}%")), | |
hjust = 0, size = 2.3, nudge_x = 0.35, color = "black", family = "Roboto Condensed") + | |
scale_y_continuous(labels = scales::percent_format(scale = 1, suffix = "%"), | |
limits = c(0, 100)) + | |
scale_color_manual(values = MetBrewer::met.brewer("Tam", direction = -1)[8]) + | |
labs(title = "5 höchste und niedrigste Quoten") + | |
coord_flip() + | |
theme_minimal(base_family = "Roboto Condensed", base_size = 9) + | |
theme(axis.title = element_blank(), | |
axis.text = element_blank(), | |
legend.position = "none", | |
plot.title = element_text(size = 9), | |
panel.grid.major.y = element_blank(), | |
panel.grid.major.x = element_line(linewidth = 0.2), | |
panel.grid.minor = element_blank()) | |
p3 <- findat |> slice_min(mittag, n = 5) |> | |
mutate(name = fct_reorder(name, mittag)) |> | |
ggplot(aes(x = name, y = mittag, color = anteil)) + | |
geom_point(size = 2) + | |
geom_segment(aes(xend = name, yend = 0), linewidth = 1.5) + | |
geom_text(y = 0, aes(label = glue::glue("{name}: {round(mittag,0)}%")), | |
hjust = 0, size = 2.3, nudge_x = 0.35, color = "black", family = "Roboto Condensed") + | |
scale_y_continuous(labels = scales::percent_format(scale = 1, suffix = "%"), | |
limits = c(0, 100)) + | |
scale_color_manual(values = MetBrewer::met.brewer("Tam", direction = -1)[1]) + | |
coord_flip() + | |
theme_minimal(base_family = "Roboto Condensed", base_size = 9) + | |
theme(axis.title = element_blank(), | |
axis.text.y = element_blank(), | |
legend.position = "none", | |
panel.grid.major.y = element_blank(), | |
panel.grid.major.x = element_line(linewidth = 0.2), | |
panel.grid.minor = element_blank()) | |
p1 + (p2 / p3) + plot_layout(widths = c(2/3, 1/3)) | |
ggsave("mittagessen.png", bg="white", width=10, height=4, dpi=320) | |
# GRAFIK: Entwicklung der Betreuungsquoten von 0-2-Jährigen seit 1995 | |
library(gghighlight) | |
library(ggrepel) | |
library(geomtextpath) | |
temp.file <- paste0(tempfile(),".ods") | |
download.file("https://www.statistik.at/fileadmin/pages/318/KTH_Betreuungsquote_2022_23.ods", | |
temp.file, mode = "wb") | |
betr <- read_ods(temp.file, sheet = "Tabelle2", | |
range = "A3:K32", col_types = "nnnnnnnnnnn") |> | |
drop_na() |> | |
rename("Wien" = "Wien1") |> | |
pivot_longer(-Jahr, names_to = "bl", values_to = "quote") |> | |
mutate(bl = str_remove_all(bl, "\\.."), | |
bl = fct_reorder(bl, quote)) | |
betr |> | |
filter(!bl == "Österreich") |> | |
ggplot(aes(x = Jahr, y = quote, color = bl)) + | |
geom_line(linewidth = 0.9) + | |
geom_text_repel(aes(label = bl, x = 2022.1), data = ~. |> slice_max(Jahr), | |
hjust = 1, size = 3, segment.size = 0.2, | |
xlim = c(2023, NA), direction = "y", | |
box.padding = unit(2, "pt"), family = "Roboto Condensed") + | |
annotate("richtext", x = 1996, y = 45, fill = NA, label.colour = NA, | |
label = "<span style='font-size:26px;font-family:\"Playfair Display\";'>Ihr Kinderlein kommet</span><br><br>Betreuungsquoten von <span style='color:#bf4f51;'>0-2-Jährigen</span><br>nach Bundesland, 1995-2022<br><br><span style='font-size:10px;'>Quelle: Statistik Austria · Grafik: @matschnetzer</span>", | |
size = 4, hjust = 0, vjust = 1, family = "Roboto Condensed", lineheight = 1.1) + | |
scale_color_manual(values = MetBrewer::met.brewer(name = "Cross")) + | |
scale_y_continuous(labels = scales::label_percent(scale = 1), | |
limits = c(0, 47), expand = c(0,0)) + | |
scale_x_continuous(limits = c(NA, 2026)) + | |
theme_minimal(base_family = "Roboto Condensed", base_size = 12) + | |
theme(axis.title = element_blank(), | |
legend.position = "none", | |
plot.title = element_text(size = 9), | |
axis.ticks.x = element_line(linewidth = 0.4, color = "gray85"), | |
panel.grid.major.x = element_blank(), | |
panel.grid.major.y = element_line(linewidth = 0.2), | |
panel.grid.minor = element_blank()) | |
ggsave("quoten.png", bg="white", width=8, height=4, dpi=320) | |
# GRAFIK: Anzahl der Kindertagesheime nach Öffnungszeiten und Bundesländer | |
library(ggchicklet) | |
temp.file <- paste0(tempfile(),".ods") | |
download.file("https://www.statistik.at/fileadmin/pages/318/KTH_Kindertagesheime_2022_23.ods", | |
temp.file, mode = "wb") | |
open <- read_ods(temp.file, sheet = "Tabelle8", | |
range = "A4:L15", col_names = T, col_types = "cnnnnnnnnnnn") |> | |
drop_na() |> | |
select(-...2) |> | |
pivot_longer(-...1, names_to = "dur", values_to = "num") | |
findat <- open |> | |
rename("bl" = ...1) |> | |
mutate(dur = str_replace_all(dur, c("X" = "", "\\." = " ")), | |
dur = fct_rev(fct_inorder(dur)), | |
dur = fct_recode(dur, "weniger als 4\nStunden" = "weniger als 4", | |
"12 und mehr\nStunden" = "12 und mehr"), | |
bl = case_match(bl, | |
"Burgenland" ~ "Bgld", | |
"Niederösterreich" ~ "NÖ", | |
"Oberösterreich" ~ "OÖ", | |
"Salzburg" ~ "Sbg", | |
"Vorarlberg" ~ "Vlbg", | |
"Steiermark" ~ "Stmk", | |
.default = bl)) | |
findat |> filter(!bl == "Österreich") |> | |
ggplot(aes(x = dur, y = num, fill = bl)) + | |
geom_chicklet(radius = unit(2, "pt")) + | |
geom_text(data = findat |> filter(bl == "Österreich"), | |
aes(label = num, x = dur, y = num+10), hjust = 0, | |
family = "Roboto Condensed", inherit.aes = F, size = 3.3) + | |
coord_flip() + | |
labs(title = "Lange Tage", | |
subtitle = "Kindertagesheime nach Anzahl der geöffneten Stunden pro Betriebstag 2022/23", | |
caption = "Daten: Statistik Austria. Grafik: @matschnetzer") + | |
guides(fill = guide_legend(nrow = 1, title = NULL, keywidth = unit(10, "pt"))) + | |
scale_fill_manual(values = MetBrewer::met.brewer(name = "Cross")) + | |
scale_y_continuous(labels = scales::label_number(big.mark = ".", decimal.mark = ","), | |
limits = c(NA, 2200), expand = c(0,0)) + | |
theme_minimal(base_family = "Roboto Condensed", base_size = 11) + | |
theme(axis.title = element_blank(), | |
legend.position = c(0.6, 0.95), | |
legend.text = element_text(size = 9, family = "Roboto Condensed"), | |
legend.spacing.x = unit(4, "pt"), | |
axis.text = element_text(lineheight = 0.9, size = 7, color = "gray20", | |
family = "Roboto Condensed"), | |
plot.title.position = "plot", | |
plot.title = element_text(family = "Fira Sans", size = 18), | |
plot.subtitle = element_text(family = "Roboto Condensed", size = 12, | |
margin = margin(b=1, unit="lines")), | |
plot.caption = element_text(size = 7, margin = margin(t=1, unit="lines")), | |
panel.grid.major.y = element_blank(), | |
panel.grid.major.x = element_line(linewidth = 0.2), | |
panel.grid.minor = element_blank()) | |
ggsave("öffnungszeiten.png", bg="white", width=8, height=4, dpi=320) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment