Last active
November 26, 2021 03:55
-
-
Save favstats/a397e2fae0a6420398be43651526b86a to your computer and use it in GitHub Desktop.
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
### Code mostly inspired by https://github.com/HudsonJamie/tidy_tuesday/blob/main/2021/week_46/afrilearndata.R | |
library(pdftools) | |
library(tidygeocoder) | |
library(tidyverse) | |
library(janitor) | |
library(rgdal) | |
library(osmdata) | |
library(sf) | |
library(ggfx) | |
library(showtext) | |
library(ggtext) | |
library(jsonlite) | |
font_add_google("Roboto", "robo") | |
showtext_opts(dpi = 600) | |
showtext_auto(enable = TRUE) | |
## Bundesärztekammer | |
text <- pdf_text("https://www.bundesaerztekammer.de/fileadmin/user_upload/downloads/pdf-Ordner/Liste219a/20211105_Liste____13_Abs_3_SchKG.pdf") | |
doctor_locs <- text %>% | |
str_split("\n") %>% | |
unlist() %>% | |
keep(~str_detect(.x, ",")) %>% | |
discard(~str_detect(.x, "Fremdsprachen|Telefon|.raxis|Gynäkologie|GmbH|Alte Potsdamer Str. 7, 10785 Berlin")) %>% | |
unique() | |
coord_doctors <- doctor_locs %>% | |
tibble(loc = .) %>% | |
mutate(loc = paste0(loc, ", Deutschland")) %>% | |
geocode(loc, method = "cascade", | |
cascade_order = c("arcgis", "osm")) | |
# load hex file from https://cartogrid.vercel.app/ | |
germany_hex <- readOGR(dsn = "../../../Downloads/Germany.geojson") | |
germany_hex_sf <- as(germany_hex, 'sf') | |
germany_bb <- getbb("Germany", | |
format_out = "sf_polygon") | |
projcrs <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" | |
germany_hospital_sf <- st_as_sf(coord_doctors, | |
coords = c("long", "lat"), | |
crs = projcrs) | |
germany_hospital_join = germany_hospital_sf %>% | |
st_union() | |
sf::sf_use_s2(FALSE) | |
distance <- st_distance(germany_hex_sf, germany_hospital_join) %>% | |
units::set_units("km") | |
germany_wf <- germany_hex %>% | |
st_as_sf() %>% | |
mutate( | |
dist = distance) %>% | |
drop_na() | |
ggplot() + | |
with_outer_glow(with_inner_glow( | |
geom_sf( | |
data = germany_wf %>% | |
mutate(dist = cut(as.numeric(dist), | |
# breaks=seq(0, 170, 50))), | |
breaks=c(-0.01, 5, 10, 15, 20, 25, 30, 35, 40, 60, 180) , | |
labels=c("0-5","5-10", | |
"10-15","15-20", "20-25", | |
"25-30","30-35", "35-40", | |
"40-60", "60+"))), | |
aes(fill = dist), | |
color = "NA", alpha = 0.95 | |
), | |
colour = "black", | |
sigma = 2 | |
), | |
colour = "white", | |
sigma = 10, | |
expand = 4) + | |
scale_fill_viridis_d(option = "inferno", direction = -1) + | |
geom_point(data = coord_doctors, | |
aes(x = long, y = lat), | |
colour = "white", size = 0.3, | |
alpha = 0.5) + | |
labs(title = "Distanz zur nächsten <span style='color:white'>***Praxis oder Klinik***</span> die<br>Schwangerschaftsabbrüche anbietet", | |
fill = "Distanz zur nächsten Praxis oder Klinik (in km)", | |
caption = "<img src='https://www.iconsdb.com/icons/preview/black/twitter-xxl.png' width='5'/>@favstats | Quelle: Bundesärztekammer (Selbstauskunft der Praxen und Kliniken)<br>") + | |
theme_void() + | |
theme(panel.background = element_rect(fill = "#d6d0da", colour = "#d6d0da"), | |
plot.background = element_rect(fill = "#d6d0da", colour = "#d6d0da"), | |
plot.title = element_markdown(hjust = 0.5, family = "robo", | |
colour = "black", | |
size = 17, | |
margin = margin(20, 0, -5, 0)), | |
plot.caption = element_markdown(family = "robo", | |
size = 6, hjust = 0.5, | |
colour = "black"), | |
legend.direction = "horizontal", | |
legend.position = "bottom", | |
# legend.key.height= unit(2, 'lines'), | |
legend.title = element_text(family = "robo", hjust = 0.5, | |
colour = "black", size = 8), | |
legend.text = element_text(colour = "black", | |
size = 5)) + | |
guides(fill = guide_legend(nrow = 1, | |
title.position = "top", | |
label.position = "bottom", | |
keyheight = unit(0.75, 'line'), | |
keywidth = unit(1.75, 'line'))) | |
ggsave(paste0("german_hospitals_", format(Sys.time(), "%d%m%Y"), ".png"), | |
dpi = 600, | |
width = 5, | |
height = 5) | |
##### https://abtreibung-adressen.eu/ | |
clinics <- jsonlite::fromJSON("https://data.abortion-clinics.eu/getClinics/") | |
coord_doctors <- clinics$clinics %>% | |
janitor::clean_names() %>% | |
filter(zipcode_region_country == 2) %>% | |
rowwise() %>% | |
mutate(coordinates_json = list(jsonlite::fromJSON(coordinates_json))) %>% | |
unnest_wider(coordinates_json) %>% | |
unnest_wider(coordinates, names_sep = "_") %>% | |
ungroup() %>% | |
rename(long = coordinates_1, lat = coordinates_2) | |
germany_hospital_sf <- st_as_sf(coord_doctors, | |
coords = c("long", "lat"), | |
crs = projcrs) | |
germany_hospital_join = germany_hospital_sf %>% | |
st_union() | |
sf::sf_use_s2(FALSE) | |
distance <- st_distance(germany_hex_sf, germany_hospital_join) %>% | |
units::set_units("km") | |
germany_wf <- germany_hex %>% | |
st_as_sf() %>% | |
mutate( | |
dist = distance) %>% | |
drop_na() | |
ggplot() + | |
with_outer_glow(with_inner_glow( | |
geom_sf( | |
data = germany_wf %>% | |
mutate(dist = cut(as.numeric(dist), | |
# breaks=seq(0, 170, 50))), | |
breaks=c(-0.01, 5, 10, 15, 20, 25, 30, 35, 40, 60, 180) , | |
labels=c("0-5","5-10", | |
"10-15","15-20", "20-25", | |
"25-30","30-35", "35-40", | |
"40-60", "60+"))), | |
aes(fill = dist), | |
color = "NA", alpha = 0.95 | |
), | |
colour = "black", | |
sigma = 2 | |
), | |
colour = "white", | |
sigma = 10, | |
expand = 4) + | |
scale_fill_viridis_d(option = "inferno", direction = -1) + | |
geom_point(data = coord_doctors, | |
aes(x = long, y = lat), | |
colour = "white", size = 0.3, | |
alpha = 0.5) + | |
labs(title = "Distanz zur nächsten <span style='color:white'>***Praxis oder Klinik***</span> die<br>Schwangerschaftsabbrüche anbietet", | |
fill = "Distanz zur nächsten Praxis oder Klinik (in km)", | |
caption = "<img src='https://www.iconsdb.com/icons/preview/black/twitter-xxl.png' width='5'/>@favstats | Quelle: abtreibung-adressen.eu<br>") + | |
theme_void() + | |
theme(panel.background = element_rect(fill = "#d6d0da", colour = "#d6d0da"), | |
plot.background = element_rect(fill = "#d6d0da", colour = "#d6d0da"), | |
plot.title = element_markdown(hjust = 0.5, family = "robo", | |
colour = "black", | |
size = 17, | |
margin = margin(20, 0, -5, 0)), | |
plot.caption = element_markdown(family = "robo", | |
size = 6, hjust = 0.5, | |
colour = "black"), | |
legend.direction = "horizontal", | |
legend.position = "bottom", | |
# legend.key.height= unit(2, 'lines'), | |
legend.title = element_text(family = "robo", hjust = 0.5, | |
colour = "black", size = 8), | |
legend.text = element_text(colour = "black", | |
size = 5)) + | |
guides(fill = guide_legend(nrow = 1, | |
title.position = "top", | |
label.position = "bottom", | |
keyheight = unit(0.75, 'line'), | |
keywidth = unit(1.75, 'line'))) | |
ggsave(paste0("german_hospitals2_", format(Sys.time(), "%d%m%Y"), ".png"), | |
dpi = 600, | |
width = 5, | |
height = 5) |
Author
favstats
commented
Nov 26, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment