|
library(tidyverse) |
|
library(pdftools) |
|
library(msthemes) |
|
library(sf) |
|
library(ggforce) |
|
library(ggrepel) |
|
sf::sf_use_s2(FALSE) |
|
|
|
# Download PDF from https://www.staedtebund.gv.at/services/publikationen/staedte-in-zahlen-oestiz/ and extract page 55 |
|
rawpdf <- pdf_text("https://www.staedtebund.gv.at/ePaper-oestiz/ausgaben-pdf/OESTIZ_2020.pdf") |
|
rawpdf <- rawpdf[55] |
|
|
|
lines <- strsplit(rawpdf, '\n') %>% unlist %>% str_trim(.,side = "left") |
|
lines <- lines[c(13:194)] |
|
|
|
df <- as.data.frame(lines) %>% |
|
separate(1,c("Gemeinde","Gesamt","HWS","NWS","Privat","Öffentlich","Gemeinnützig","Sonstige","Wohnungslos"), sep="\\s+\\s+") %>% |
|
filter(!is.na(Gesamt)) %>% |
|
mutate_at(.vars = -1, list(~as.numeric(gsub("\\.", "", .)))) %>% |
|
replace(is.na(.),0) %>% |
|
mutate_at(.vars = 1, list(~str_replace_all(.,c( |
|
"Bgl.Eisenstadt" = "Eisenstadt", |
|
"Saalfelden/Steinernen Meer" = "Saalfelden am Steinernen Meer", |
|
"TirolSchwaz" = "Schwaz") |
|
))) |
|
|
|
# Manually deleting Bundesländer |
|
df <- df[-c(76:85),] |
|
|
|
# Get map from https://github.com/ginseng666/GeoJSON-TopoJSON-Austria |
|
map <- st_read("https://raw.githubusercontent.com/ginseng666/GeoJSON-TopoJSON-Austria/master/2017/simplified-99.9/gemeinden_999_geo.json", quiet=TRUE, stringsAsFactors=FALSE) |> |
|
mutate( |
|
center = map(geometry, st_centroid), |
|
centercoord = map(center, st_coordinates), |
|
ccordx = map_dbl(centercoord, 1), |
|
ccordy = map_dbl(centercoord, 2) |
|
) |
|
|
|
# Breaks for shares of social housing |
|
breaks <- c(0,20,35,50,100) |
|
df$social <- (df$Gemeinnützig + df$Öffentlich)/df$Gesamt*100 |
|
df$socialcat <- cut(df$social, breaks) |
|
|
|
mapdat <- left_join(map,df,by= c("name"="Gemeinde")) |> filter(!is.na(social)) |
|
|
|
set.seed(1238) |
|
|
|
mapdat |> ggplot() + |
|
geom_sf(data=st_union(map), fill="gray99", linewidth = 0.5) + |
|
coord_sf(datum = NA) + |
|
geom_point(aes(x=ccordx, y=ccordy, color=socialcat, size=Gesamt), |
|
data=mapdat |> filter(!is.na(social))) + |
|
scale_size(name = "Wohnungen", |
|
breaks = c(50000,250000,500000), |
|
labels = c("50.000","250.000","500.000"), |
|
range = c(1, 7)) + |
|
scale_colour_manual(name="Anteil", |
|
labels = c("<20%","20-35%","35-50%",">50%"), |
|
values = c("#189ad3","#ffc300","#1e8449","#C70039")) + |
|
theme_ms(alt=T) + |
|
guides(colour = guide_legend(override.aes = list(size=4))) + |
|
labs(x="",y="", |
|
title = "Sozialer Wohnbau in Österreich", |
|
subtitle = "Anteil der öffentlichen und gemeinnützigen Wohnungen in Gemeinden über 11.000 Einwohnern", |
|
caption = "Quelle: Städte in Zahlen 2020, Städtebund. Grafik: @matschnetzer") + |
|
geom_mark_circle(aes(x=ccordx,y=ccordy, |
|
filter = name == "Feldkirch", label = "Feldkirch", |
|
description = "In Feldkirch sind nur 15% der Wohnungen in öffentlichem oder gemeinnützigem Eigentum"), |
|
label.buffer = unit(10,"mm"), |
|
label.fontsize = c(9, 7), |
|
label.minwidth = unit(55,"mm"), |
|
expand = unit(3,"mm"), |
|
con.cap = 2) + |
|
geom_mark_circle(aes(x=ccordx,y=ccordy, |
|
filter = name == "Linz", label = "Linz", |
|
description = "Linz hat mit mehr als 55% den höchsten Anteil an sozialem Wohnbau"), |
|
label.buffer = unit(14,"mm"), |
|
label.fontsize = c(9, 7), |
|
expand = unit(3,"mm"), |
|
con.cap = 2) + |
|
geom_label_repel(aes(x=ccordx, y=ccordy, |
|
label = glue::glue("{name} ({round(social,0)}%)")), |
|
data = subset(mapdat |> |
|
filter(name %in% c("Knittelfeld", "Kapfenberg", "Wien"))), |
|
size = 2.3, |
|
box.padding = 0.4, |
|
label.size = 0.15, |
|
segment.size = 0.1, |
|
nudge_x = c(1,0,0)) |
|
|
|
ggsave("socialhousing.png", dpi=320, width = 9, height = 5) |