# NOT RUN {
# Get munics
Base <- esp_get_munic(year = "2019", region = "Castilla y Leon")
# Provs for delimiting
provs <- esp_get_prov(prov = "Castilla y Leon")
# Load population data
data("pobmun19")
# Arrange and create breaks
Base_pop <- merge(Base, pobmun19,
by = c("cpro", "cmun"),
all.x = TRUE
)
br <- sort(c(
0, 50, 100, 200, 500,
1000, 5000, 50000, 100000,
Inf
))
Base_pop$cuts <- cut(Base_pop$pob19, br, dig.lab = 20)
# Plot
library(ggplot2)
ggplot(Base_pop) +
geom_sf(aes(fill = cuts), color = NA) +
geom_sf(data = provs, fill = NA, color = "grey70") +
scale_fill_manual(values = hcl.colors(length(br), "cividis")) +
labs(
title = "Population in Castilla y Leon",
subtitle = "INE, 2019",
fill = "Persons"
) +
theme_void()
# }
Run the code above in your browser using DataLab