【R】mapSpain
2020年12月13日
1. はじめに
mapSpainは、スペインのデータです。
2. インストール
CRANからインストールできます。
install.packages("mapSpain")
3. 使ってみる
library(mapSpain)
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
census <- mapSpain::pobmun19
# Paste CCAA
census <-
unique(merge(census, esp_codelist[, c("cpro", "codauto")], all.x = TRUE))
# Summarize
census_ccaa <-
aggregate(cbind(pob19, men, women) ~ codauto, data = census, sum)
census_ccaa$porc_women <- census_ccaa$women / census_ccaa$pob19
CCAA.sf <- esp_get_ccaa()
# Merge data
CCAA.sf <- merge(CCAA.sf, census_ccaa)
# Choropleth map
library(cartography)
br <- getBreaks(CCAA.sf$porc_women, method = "pretty")
pal <- hcl.colors(length(br) - 1,
palette = "Blues 3",
rev = TRUE,
alpha = 0.8
)
choroLayer(
CCAA.sf,
var = "porc_women",
breaks = br,
legend.values.rnd = 3,
legend.pos = "bottomright",
col = pal,
border = NA,
legend.title.txt = "% women"
)
# Add lines
CCAAbox <- esp_get_can_box()
plot(CCAAbox, add = TRUE, col = pal[length(pal)])

4. さいごに
スペインに行ったことがないので、行ってみたい!