Created
April 29, 2021 09:29
-
-
Save mschnetzer/24347c59a826c9710ae7b79310e3afea to your computer and use it in GitHub Desktop.
Arbeitslosenraten für Österreich 1960-2020 (https://twitter.com/matschnetzer/status/1387385070718173185?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(ragg) | |
library(showtext) | |
# get data from https://www.oenb.at/isaweb/report.do?lang=DE&report=7.17 | |
unemp <- vroom::vroom("unemployment.csv") | |
font_add_google("Abel", "abel") | |
font_add_google("Raleway", "raleway") | |
showtext_opts(dpi = 320) | |
showtext_auto(enable = TRUE) | |
monthly <- unemp %>% | |
filter(indicator == "Unemployment rate (national definition), M-end NSA", | |
period == "month", | |
year %in% 1960:2020) %>% | |
select(year, month, values) %>% | |
mutate(color = case_when(year %in% 1990:2019 ~ "Recent", | |
year %in% 1960:1989 ~ "Past", | |
TRUE ~ "ZCorona"), | |
month = as.numeric(month)) | |
axis_labels <- tibble(month = lubridate::month(seq(1,12,1), label = TRUE), | |
pos = seq(1,12,1)) | |
ggplot() + | |
# empty tile to get a legend with rectangle key | |
geom_tile(data = monthly, aes(x = 0, y =0, width =0, height = 0, fill = color)) + | |
# y-axis | |
geom_segment(aes(x = 0, xend = 12.5, y = seq(0,12,2), yend = seq(0,12,2)), color = "white", linetype = "12", size = 0.1) + | |
geom_text(aes(x = 0, y = seq(0,12,4), label = paste0(seq(0,12,4),"%")), color = "white", nudge_y = 0.3, family = "raleway", hjust = 0, size = 3) + | |
geom_text(aes(x = 12.5, y = 0.2), label = "Daten: OeNB. Grafik: @matschnetzer", color = "white", family = "abel", hjust = 1, size = 2.25) + | |
# show.legend = FALSE to remove the shape of the point in the legend | |
geom_jitter(data = filter(monthly, color == "Recent" & year < 2020), aes(x = month+0.1, y = values, fill = color), width = 0.15, height =0, size = 3, shape = 21, stroke = 0.3, color = "#FFDADC", show.legend = FALSE) + | |
geom_jitter(data = filter(monthly, color == "Past"), aes(x = month-0.1, y = values, fill = color), width = 0.15, height =0, size = 2.5, shape = 21, stroke = 0.3, color = "#93E2F5", show.legend = FALSE) + | |
geom_point(data = filter(monthly, color == "ZCorona"), aes(x = month, y=values, fill = color), size = 3, shape = 21, stroke = 0.3, color = "white", show.legend = FALSE) + | |
# x-axis labels | |
geom_text(data = axis_labels, aes(x = pos, y = -1, label = month), color = "white", vjust = 0, angle = 0, family = "raleway", size = 3)+ | |
# scales | |
scale_fill_manual(values = c("Recent" = "#f1434a", "Past" = "steelblue3", "ZCorona" = "darkgoldenrod1"), labels = c("Recent" = "1990-2019", "Past" = "1960-1989", "ZCorona" = "2020")) + | |
# scale_y_continuous(limits = c(-1,14)) + | |
labs(fill = "Arbeitslosenrate in Österreich") + | |
theme_void() + | |
guides(fill = guide_legend(label.position = "top", | |
title.hjust = 0.5, title.vjust = -6, | |
label.vjust = -8, | |
keyheight = unit(1, "line"), | |
keywidth = unit(3.5, "line"), | |
nrow = 1), | |
color = FALSE) + | |
theme(plot.background = element_rect(fill = "lightsteelblue4", color = NA), | |
legend.position = c(0.68,0.87), | |
legend.text = element_text(family = "raleway", | |
size = 9, color = "black"), | |
legend.title = element_text(family = "raleway", | |
size = 12, color = "white")) + | |
ggsave("arbeitslosigkeit.png", dpi = 320, height = 4, width = 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment