Skip to content

Instantly share code, notes, and snippets.

@long39ng
Last active Sep 16, 2021
Embed
What would you like to do?
library(tidyverse)
library(sf)
library(stars)
# Migrazensus dataset downloaded from: https://doi.org/10.7910/DVN/GPEV4P
migrazensus <- read_csv(here::here("migrazensus_v0.2.csv")) |>
mutate(wknr_2021 = as.double(wknr_2021))
# Shape files downloaded from
# https://www.bundeswahlleiter.de/dam/jcr/67e3e9b8-dbca-4bc9-8977-ac792665bbce/btw17_geometrie_wahlkreise_vg250_shp.zip
wk_sf <- st_read(here::here("shapefiles/Geometrie_Wahlkreise_20DBT_VG250.shp"), as_tibble = TRUE)
migra_sf <- wk_sf |>
select(WKR_NR, geometry) |>
left_join(migrazensus, by = c("WKR_NR" = "wknr_2021")) |>
relocate(geometry, .after = everything()) |>
mutate(non_eligible = (mighintergrund_absolut - wbmighintergrund_absolut) / bevoelkerung)
migra_raster <- migra_sf |>
select(non_eligible) |>
st_rasterize(dx = 6000, dy = 6000)
migra_tbl <- migra_raster |>
as("Raster") |>
landscapetools::util_raster2tibble() |>
group_by(x) |>
mutate(z = slider::slide_dbl(z, mean, .before = 1, .after = 1)) |>
ungroup() |>
group_by(y) |>
mutate(z = slider::slide_dbl(z, mean, .before = 1, .after = 1)) |>
ungroup()
ragg::agg_png("ridge_lat_log_bloom.png", 210, 297, "mm", res = 300, background = "#121212")
migra_tbl |>
ggplot(aes(x, y + 12 * (z / max(z, na.rm = TRUE)))) +
ggfx::with_bloom(geom_line(
aes(colour = z, group = fct_rev(factor(y))),
na.rm = TRUE,
size = .9,
lineend = "round"
)) +
colorspace::scale_colour_continuous_sequential("Turku", trans = "log") +
labs(
title = "Proportion of persons with a migration background\nwho are not entitled to vote in the population",
caption = "Data: *Migrazensus* (2021)<br>doi.org/10.7910/DVN/GPEV4P"
) +
coord_equal() +
theme_void(base_size = 20) +
theme(
legend.position = "none",
plot.title = element_text(family = "D-DIN Condensed", colour = "white", face = "bold", hjust = .5),
plot.title.position = "plot",
plot.caption = ggtext::element_markdown(family = "D-DIN", colour = "white", lineheight = 1.3),
plot.caption.position = "plot",
plot.margin = margin(l = 15, r = 15, unit = "mm")
)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment