Skip to content

Instantly share code, notes, and snippets.

@mschnetzer
Created December 1, 2022 08:08
Show Gist options
  • Save mschnetzer/4f10aff5401f37d67c0c567cc0e46c3f to your computer and use it in GitHub Desktop.
Save mschnetzer/4f10aff5401f37d67c0c567cc0e46c3f to your computer and use it in GitHub Desktop.
librarian::shelf(tidyverse, pdftools, msthemes, ggtext, showtext)
# Add Google fonts
font_add_google("Alfa Slab One", "alfa")
font_add_google("Roboto Mono", "space", regular.wt = 200)
showtext_opts(dpi = 320)
showtext_auto(enable = TRUE)
# Download PDF:
# https://www.oegb.at/content/dam/oegb/downloads/der-ögb/Streikstatistik_2021.pdf
streik <- pdf_text("Streikstatistik_2021.pdf")
# Read 1st page of PDF
strikes1 <- unlist(strsplit(streik[1], split = "\n")) |>
str_split_fixed(" {2,}", 7) |> as.data.frame() |> select(-V1) |>
mutate(across(everything(), ~stringr::str_replace_all(., "\\.", ""))) |>
mutate(across(everything(), ~stringr::str_extract_all(., "[[:digit:]]+", ))) |>
mutate(across(everything(), ~as.numeric(.))) |> filter(V2 > 1900) |>
mutate(across(everything(), ~replace_na(., 0)))
# Read 2nd page of PDF
strikes2 <- unlist(strsplit(streik[2], split = "\n")) |>
str_split_fixed(" {2,}", 7) |> as.data.frame() |>
mutate(across(everything(), ~stringr::str_replace_all(., "\\.", ""))) |>
mutate(across(everything(), ~stringr::str_extract_all(., "[[:digit:]]+", ))) |>
mutate(across(everything(), ~as.numeric(.))) |> filter(V1 > 1900) |>
mutate(across(everything(), ~replace_na(., 0)))
# Merge columns in long table
part1 <- strikes1 |> select(Jahr = V2, Beteiligte = V3, Streikstunden = V4)
part2 <- strikes1 |> select(Jahr = V5, Beteiligte = V6, Streikstunden = V7)
part3 <- strikes2 |> select(Jahr = V1, Beteiligte = V2, Streikstunden = V3)
strikes <- bind_rows(part1,part2,part3)
dark <- "gray10"
col1 <- msl_palette[2]
col2 <- msl_palette[5]
strikes |> ggplot() +
geom_area(aes(x = Jahr, y = -Streikstunden), linewidth = 0.7,
fill = col1, color = col1) +
geom_area(aes(x = Jahr, y = Beteiligte*10), linewidth = 0.7,
fill = col2, color = col2)+
geom_hline(yintercept = 0, linewidth = 0.8, color = dark) +
geom_curve(aes(x=1992, xend=2003, y=-11.5e6, yend=-10.6e6),
curvature = 0.2, color = "grey80", linewidth = 0.1,
arrow = arrow(ends = "last", type = "open", length = unit(2, "pt"))) +
geom_curve(aes(x=1975, xend=1962, y=4e6, yend=2.3e6),
curvature = 0.2, color = "grey80", linewidth = 0.1,
arrow = arrow(ends = "last", type = "open", length = unit(2, "pt"))) +
geom_curve(aes(x=1950, xend=1950, y=-8.5e6, yend=-4.2e6),
curvature = -0.1, color = "grey80", linewidth = 0.1,
arrow = arrow(ends = "last", type = "open", length = unit(2, "pt"))) +
annotate(geom = "label", x = 1954, y = -10.5e6, label = str_wrap("Der Oktoberstreik 1950 im Zuge des Lohn-Preis-Abkommens ist der bekannteste und politisch umstrittenste Streik der Nachkriegszeit. Gestreikt wurde u.a. bei VÖEST, ÖBB, Post und Steyr Daimler Puch.", 30), size = 1.8, family = "space", color = "white", hjust = 0, fill = dark, label.padding = unit(4, "pt"), label.size = 0.1) +
annotate(geom = "label", x = 1978, y = 1.5e6, label = str_wrap("Vom 9. bis zum 12. Mai 1962 streiken rund 200.000 Metallarbeiter:innen. Die Streikenden forderten erfolgreich Verbesserungen bei Löhnen, Arbeitsrecht und Arbeitsbedingungen von Frauen.", 50), size = 1.8, family = "space", color = "white", hjust = 0, fill = dark, label.padding = unit(4, "pt"), label.size = 0.1) +
annotate(geom = "label", x = 1992, y = -11.5e6, label = str_wrap("2003 streikten knapp 780.000 Beschäftigte insgesamt mehr als 10 Mio. Arbeitsstunden gegen Pensionskürzungen sowie in Arbeitskämpfen bei ÖBB und AUA. Es war der größte Streik der 2. Republik.", 50), size = 1.8, family = "space", color = "white", hjust = 0, fill = dark, label.padding = unit(4, "pt"), label.size = 0.1) +
scale_y_continuous(breaks = c(-1e7, -7.5e6, -5e6, -2.5e6, 0, seq(2e6, 8e6, 2e6)),
labels = c("10 Mio.", "7,5 Mio.", "5 Mio.", "2,5 Mio.", 0, "200T", "400T", "600T", "800T")) +
scale_x_continuous(trans = "reverse") +
coord_flip() +
labs(x = NULL, y = NULL,
title = "Streiks in Österreich",
subtitle = "<span style='color:#f37736'>Streikstunden</span> und <span style='color:#0392cf'>Streikbeteiligte</span> seit 1945",
caption = "Quelle: ÖGB. Grafik: @matschnetzer") +
theme_ms(dark = T) +
theme(panel.grid.major = element_line(linewidth = 0.05),
plot.background = element_rect(fill = dark),
plot.title = element_text(family = "alfa", size = 25, color = "white"),
plot.subtitle = element_markdown(family = "alfa", margin = margin(b=10, t=7), size = 12),
plot.caption = element_text(family = "space", margin = margin(t=10), size = 6),
axis.text = element_text(family = "space", size = 8))
ggsave("strike.png", width = 7, height = 4, dpi = 320)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment