Created
October 23, 2025 16:58
-
-
Save bastianolea/52259ec4964891b2d11c5ad59c010246 to your computer and use it in GitHub Desktop.
visualizar un mapa de Chile separado en tres secciones
This file contains hidden or 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
| # Visualizar un mapa de Chile separado en tres secciones | |
| # https://bastianolea.rbind.io/blog/mapa_chile_triple/ | |
| # mapas ---- | |
| # descargar | |
| download.file("https://www.bcn.cl/obtienearchivo?id=repositorio/10221/10398/2/Regiones.zip", | |
| "Regiones.zip") | |
| # descomprimir | |
| unzip("Regiones.zip", exdir = "Regiones") | |
| # cargar ---- | |
| mapa <- read_sf("Regiones") | |
| # limpieza ---- | |
| # # borrar archivo comprimido | |
| # file.remove("Regiones.zip") | |
| # | |
| # # borrar carpeta con shapes | |
| # unlink("Regiones", recursive = TRUE) | |
| # simplificar ---- | |
| mapa <- mapa |> rmapshaper::ms_simplify(keep = 0.007) | |
| # mapa base ---- | |
| mapa_base <- mapa |> | |
| # reproyectar | |
| st_transform(crs = 5360) |> | |
| # visualizar | |
| ggplot() + | |
| geom_sf() + | |
| theme_minimal(base_size = 8) | |
| # separar ---- | |
| mapa_norte <- mapa_base + | |
| coord_sf(expand = FALSE, | |
| xlim = c(-74, -65), | |
| ylim = c(-17.3, -30.2)) | |
| mapa_centro <- mapa_base + | |
| coord_sf(expand = FALSE, | |
| xlim = c(-76, -68), | |
| ylim = c(-30.2, -43.2)) | |
| mapa_sur <- mapa_base + | |
| coord_sf(expand = FALSE, | |
| xlim = c(-78, -65), | |
| ylim = c(-43.2, -56.2)) | |
| # unir mapas | |
| mapa_norte + mapa_centro + mapa_sur + | |
| plot_annotation(title = "Mapa de Chile", | |
| subtitle = "dividido en tres secciones") & | |
| theme(axis.text.x = element_blank()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment