Wealth boundaries
[This article was first published on r.iresmi.net, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Day 27 of 30DayMapChallenge: « Boundaries » (previously).
There are still borders in Europe: wealth is not distributed equally. We can show the difference of gross domestic product (GDP) per capita at the NUTS 2 level.
Config
library(sf) library(glue) library(janitor) library(dplyr) library(readxl) library(mapsf) library(ggplot2) library(ggspatial) library(rnaturalearth)
Data
# NUTS 2
# https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units/territorial-units-statistics
nuts <- read_sf("NUTS_RG_60M_2024_3035.gpkg") |>
clean_names() |>
filter(levl_code == 2)
# GDP
# https://ec.europa.eu/eurostat/databrowser/view/nama_10r_2gdp__custom_19106190/default/table
# Euro per inhabitant / Display settings : codes
gdp <- read_xlsx("nama_10r_2gdp__custom_19106190_spreadsheet.xlsx",
skip = 8,
sheet = "Sheet 1",
col_types = c("text", "text", "numeric", "text"),
.name_repair = make_clean_names) |>
rename(gdp_cap = x)
# From Natural Earth
world <- ne_countries(scale = 110) |>
st_transform("EPSG:3035")
non_europe <- world |>
st_filter(nuts |>
st_point_on_surface() |>
st_union(), .predicate = st_disjoint)
# Add GDP data to the geom
gdp_nuts <- nuts |>
left_join(gdp,
join_by(nuts_id == geo_codes)) |>
select(nuts_id, nuts_name, gdp_cap)
# find borders and compute sides difference
nuts_contig <- mf_get_borders(gdp_nuts) |>
mutate(diff = abs(gdp_cap.1 - gdp_cap))
Map
gdp_nuts |>
ggplot() +
geom_sf(data = non_europe, color = "grey", fill = "white") +
geom_sf(aes(fill = gdp_cap / 1000)) +
geom_sf(data = filter(nuts_contig, diff > 10000),
aes(linewidth = diff / 1000),
color = "red", lineend = "round") +
scale_linewidth_binned(breaks = c(10, 25, 50, 75),
range = c(0.1, 3),
transform = "log") +
scale_fill_viridis_c(na.value = "#dddddd") +
annotation_scale(height = unit(1, "mm"),
text_col = "darkgrey", line_col = "grey",
bar_cols = c("white", "grey")) +
coord_sf(xlim = c(2500000, 7350000),
ylim = c(1450000, 5350000)) +
labs(title = "Gross domestic product boundaries",
subtitle = glue("GDP in Europe"),
fill = "GDP/capita\n(k€)",
linewidth = "GDP/capita\ndifference (k€)",
caption = glue("data: Eurostat, Natural Earth
https://r.iresmi.net - {Sys.Date()}")) +
theme_void() +
theme(plot.caption = element_text(size = 7, color = "grey40"),
plot.margin = unit(c(.2, .2, .2, .2), units = "cm"),
legend.position = "bottom")
To leave a comment for the author, please follow the link and comment on their blog: r.iresmi.net.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.