Skip to content

Instantly share code, notes, and snippets.

@bastianolea
Created October 16, 2025 14:37
Show Gist options
  • Select an option

  • Save bastianolea/a9e7af5392a31251e33f68ca041e8dd6 to your computer and use it in GitHub Desktop.

Select an option

Save bastianolea/a9e7af5392a31251e33f68ca041e8dd6 to your computer and use it in GitHub Desktop.
Mapa de Chile en base a datos geoespaciales oficiales de Subdere, hecho en R
# https://ide.subdere.gov.cl/descargas-con-filtros/
# descargar ----
dir.create("shapes")
download.file("https://ide.subdere.gov.cl/wp-content/uploads/74_limites_dpa_2022.zip",
"shapes/74_limites_dpa_2022.zip")
download.file("https://ide.subdere.gov.cl/descargas/SHP/Limite_DPA_03082023.rar",
"shapes/Limite_DPA_03082023.rar")
download.file("https://ide.subdere.gov.cl/descargas/SHP/Municipios_15112022.zip",
"shapes/Municipios_15112022.zip")
download.file("https://www.bcn.cl/obtienearchivo?id=repositorio/10221/10403/2/Red_Vial.zip",
"shapes/Red_Vial.zip")
# censo_region_total <- read_sf("shapes/censo_2017/R01", layer = "DISTRITO_C17") |> clean_names()
# sum(censo_region_total$total_pers)
# cargar ----
library(sf)
library(dplyr)
# división político-administrativa
dpa <- read_sf("shapes/DPA_2023/COMUNAS") |>
janitor::clean_names() |>
mutate(geometry = rmapshaper::ms_simplify(geometry, keep = 0.01, keep_shapes = TRUE))
# límites comunales
limites <- read_sf("shapes/74_limites_dpa_2022") |>
janitor::clean_names() |>
mutate(geometry = rmapshaper::ms_simplify(geometry, keep = 0.05, keep_shapes = TRUE))
# ubicación de municipalidades
municipios <- read_sf("shapes/Municipios_15112022") |>
janitor::clean_names()
# red vial del MOP
calles <- read_sf("shapes/Red_Vial") |>
janitor::clean_names() |>
# # sistema de coordenadas
# # st_transform(crs = st_crs(dpa)) |>
# group_by(cod_region, clase_ruta) |>
# summarize(geometry = st_union(geometry)) |>
# ungroup() |>
# simplificar geometrías
mutate(geometry = rmapshaper::ms_simplify(geometry, keep = 0.0001, keep_shapes = TRUE))
# mapa ----
library(ggplot2)
ggplot() +
geom_sf(data = dpa, aes(fill = region), linewidth = 0) +
geom_sf(data = limites, color = "peachpuff4", linewidth = 0.2, alpha = 0.8) + #|> blend("multiply") +
geom_sf(data = calles |> filter(clase_ruta <= 3), color = "peachpuff4", linewidth = 0.1, alpha = 0.6) +
geom_sf(data = municipios, color = "peachpuff4", size = 0.8, alpha = 0.6) +
geom_sf(data = municipios, color = "cornsilk1", size = 0.1, alpha = 0.9) +
# recortar chile continental
coord_sf(expand = FALSE,
xlim = c(-76, -66),
# ylim = c(-25, -30),
ylim = c(-56.2, -17)
) +
# paleta
colorspace::scale_fill_discrete_qualitative(
palette = "Warm",
c1 = 40, # chroma
l1 = 85 # luminancia
) +
# theme_minimal() +
theme_void() +
theme(legend.position = "none") +
ggview::canvas(4, 11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment