Created
December 17, 2025 20:01
-
-
Save bastianolea/a45ba0b6a068c7e42c3054e070d4c04d to your computer and use it in GitHub Desktop.
Código para visualizar mapas interactivos con los datos del Censo 2024 a nivel de manzana con R
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
| # código para visualizar mapas interactivos con los datos del Censo 2024 a nivel de manzana con R con {mapgl} | |
| library(dplyr) | |
| library(arrow) | |
| library(mapgl) | |
| manzanas <- read_parquet("datos/Cartografia_censo2024_Pais/Cartografia_censo2024_Pais_Manzanas.parquet") | |
| manzanas |> names() | |
| manzanas |> glimpse() | |
| library(sf) | |
| # manzanas por comuna ---- | |
| # filtrar | |
| manzanas_comuna <- manzanas |> | |
| filter(COMUNA == "ANGOL") | |
| # convertir a sf | |
| manzanas_comuna_sf <- manzanas_comuna |> | |
| st_as_sf(crs = 4326) |> | |
| select(REGION, n_edad_60_mas, SHAPE) |> | |
| rename(geometry = SHAPE) | |
| # para usar mapbox se necesita un token en .Renviron | |
| # usethis::edit_r_environ() | |
| # así que usaremos maplibre | |
| maplibre() | |
| mapa_comuna <- manzanas_comuna_sf |> | |
| maplibre_view(column = "n_edad_60_mas", | |
| palette = \(n) RColorBrewer::brewer.pal(n, "RdPu") | |
| ) | |
| mapa_comuna | |
| # manzanas por región ---- | |
| # filtrar | |
| manzanas_region <- manzanas |> | |
| filter(REGION == "METROPOLITANA DE SANTIAGO") | |
| # convertir a sf | |
| manzanas_region_sf <- manzanas_region |> | |
| st_as_sf(sf_column_name = "SHAPE", crs = 4326) |> | |
| select(REGION, n_edad_60_mas, SHAPE) |> | |
| rename(geometry = SHAPE) | |
| # generar mapa interactivo | |
| mapa_region <- manzanas_region_sf |> | |
| maplibre_view(column = "n_edad_60_mas", | |
| palette = \(n) RColorBrewer::brewer.pal(n, "PRGn")) | |
| # ver | |
| mapa_region |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment