Created
December 12, 2025 16:53
-
-
Save bastianolea/8e3dff701fb660ee7cb5091bd1195b5f to your computer and use it in GitHub Desktop.
código de R para rotar un mapa de Chile para que quede horizontal
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
| library(ggplot2) # visualización de datos | |
| library(dplyr) # manejo de datos tabulares | |
| library(chilemapas) # mapas de chile | |
| # obtener mapa | |
| mapa_region <- chilemapas::generar_regiones() | |
| # reprojectar a CRS EPSG:5361 para evitar deformación | |
| mapa_proyectado <- st_transform(mapa_region, 5361) | |
| # matriz de rotación 90° izquierda | |
| rotacion <- matrix(c(0, -1, 1, 0), 2, 2) | |
| # aplicar rotación al mapa proyectado | |
| mapa_rotado <- mapa_proyectado |> | |
| mutate(geometry = geometry * rotacion) | |
| # visualizar | |
| mapa_rotado |> | |
| ggplot() + | |
| geom_sf(linewidth = 0.2) + | |
| scale_y_continuous(labels = scales::label_number()) + | |
| coord_sf(ylim = c(800000, -100000)) + | |
| labs(title = "Mapa de Chile horizontal", | |
| subtitle = "A mimir") + | |
| scale_fill_distiller(type = "seq", palette = 12, | |
| labels = scales::label_comma(big.mark = ".")) + | |
| guides(fill = guide_legend(position = "bottom")) + | |
| theme_classic() + | |
| theme(axis.text = element_blank(), | |
| axis.line = element_blank(), | |
| axis.ticks = element_blank()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment