jacobavina@ieee.org

knitr::opts_chunk$set(echo = TRUE)

library(RColorBrewer)
library(sf)
library(maptools)
library(tidyverse) # wickham2020
library(bbplot)
library(wesanderson)
library(jcolors)
library(RColorBrewer)
library(DT)        # xie2020

INTRODUCCIÓN

Ciudad de México 2021 (Escala 1:250000)

  • Información de https://r-spatial.github.io/sf/.

  • Aquí se muestra un resumen de los datos que componen los archivos Shapefile. El dato geográfico es el límite territorial, la clave de estado para la Ciudad de México es el 09 y la geometría es una serie de datos en forma de objeto.

cdmx_shp <- st_read("889463770305_s/conjunto_de_datos/limite250_l.shp")
## Reading layer `limite250_l' from data source 
##   `C:\Users\jmm_j\OneDrive\Documentos\AZUR\datos\azur\889463770305_s\conjunto_de_datos\limite250_l.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 1 feature and 6 fields
## Geometry type: LINESTRING
## Dimension:     XY
## Bounding box:  xmin: -99.36492 ymin: 19.04824 xmax: -98.9403 ymax: 19.59276
## Geodetic CRS:  Mexico ITRF2008
datatable(data = head(cdmx_shp), rownames = FALSE)
  • Obtuve las capas topográficas de los límites territoriales por entidad, utilizo de ejemplo la Ciudad de México.
cdmx_shp <- cdmx_shp %>% select(geometry)

ggplot(cdmx_shp) +
  geom_sf()

  • Adicionalmente agregué la capa de las curvas de nivel de la entidad únicamente para demostrar las posibilidades de observación disponibles. La base de datos cuenta con los siguientes catálogos.

    • áreas_geoestadísticas_estatales
    • áreas_geoestadísticas_municipales
    • localidades_urbanas_y_rurales_amanzanadas
    • localidades_rurales_que_rebasan_su_ municipio
    • localidades_urbanas_que_rebasan_su_municipio
    • localidades_rurales_que_rebasan_AGEB
    • localidades_islas (localidades que se ubican en un municipio y administrativamente pertenecen a otro municipio)
cdmx_shp_curvanivel <- st_read("889463770305_s/conjunto_de_datos/curva_nivel250_l.shp") %>% 
               select(geometry)
## Reading layer `curva_nivel250_l' from data source 
##   `C:\Users\jmm_j\OneDrive\Documentos\AZUR\datos\azur\889463770305_s\conjunto_de_datos\curva_nivel250_l.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 254 features and 7 fields
## Geometry type: LINESTRING
## Dimension:     XY
## Bounding box:  xmin: -99.36351 ymin: 19.04867 xmax: -98.95254 ymax: 19.59223
## Geodetic CRS:  Mexico ITRF2008
cdmx_shp_union <- rbind(cdmx_shp, cdmx_shp_curvanivel)

ggplot(cdmx_shp_union) +
  geom_sf()

  • Agregué unas líneas de intersección para ejemplificar cómo ubicar un punto específico conforme a la latitud y longitud del emplazamiento a trabajar.
mg2022_cdmx <- st_read("889463770541_s/mg2022_integrado/conjunto_de_datos/00ent.shp") %>% 
          filter(CVE_ENT == "09")
## Reading layer `00ent' from data source 
##   `C:\Users\jmm_j\OneDrive\Documentos\AZUR\datos\azur\889463770541_s\mg2022_integrado\conjunto_de_datos\00ent.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 32 features and 3 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 911292 ymin: 319149.1 xmax: 4083063 ymax: 2349615
## Projected CRS: MEXICO_ITRF_2008_LCC
ggplot(mg2022_cdmx) +
  geom_sf() +
  annotate("point", x = -99.25, y = 19.32, colour = "red", size = 4) +
  coord_sf(default_crs = sf::st_crs(4326)) +
  geom_sf_label(aes(label = "Lat: 19.32
Lon: -99.25"), nudge_x = 0.01, nudge_y = 0.06) +
  geom_hline(yintercept = 19.32, lwd = 0.1, colour="red")+
  geom_vline(xintercept = -99.25, lwd = 0.1, colour="red") +
  labs(title = "Ciudad de México",
       x = "",
       y="")

  • Este mismo ejercicio se puede realizar con el resto de la República Mexicana.
mg2022 <- st_read("889463770541_s/mg2022_integrado/conjunto_de_datos/00ent.shp")
## Reading layer `00ent' from data source 
##   `C:\Users\jmm_j\OneDrive\Documentos\AZUR\datos\azur\889463770541_s\mg2022_integrado\conjunto_de_datos\00ent.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 32 features and 3 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 911292 ymin: 319149.1 xmax: 4083063 ymax: 2349615
## Projected CRS: MEXICO_ITRF_2008_LCC
ggplot(mg2022) +
  geom_sf()

Agregando estadísticas

  • Agregué los datos estadísticos para el análisis. Sin embargo, no es posible identificar debidamente lo que se está representando con cada elemento.
cat_indice_peligro <- st_read("Categorizacion del indice de peligro por tormentas electricas a nivel municipal/Categorizacion del indice de peligro por tormentas electricas a nivel municipal.shp")
## Reading layer `Categorizacion del indice de peligro por tormentas electricas a nivel municipal' from data source `C:\Users\jmm_j\OneDrive\Documentos\AZUR\datos\azur\Categorizacion del indice de peligro por tormentas electricas a nivel municipal\Categorizacion del indice de peligro por tormentas electricas a nivel municipal.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 2456 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 907821.8 ymin: 319149.1 xmax: 4082997 ymax: 2349615
## Projected CRS: North_America_Lambert_Conformal_Conic
ggplot(cat_indice_peligro) +
  geom_sf()

# theme_dark()
# theme_void()

 # finalise_plot(plot_name = mybbplot1,
#               source = "Con información de OPIS APAC Solar Weekly. Agosto 2023.",
#               save_filepath = "map_chart_1.png",
#               width_pixels = 500,
#               height_pixels = 500,
#               logo_image_path = "Color logo.png")
  • Para identificar visualmente la información agregamos color a las escalas.
ggplot(cat_indice_peligro) +
  geom_sf(aes(fill = IP_TorEle)) 

  • Cambié la escala de colores por una escala de amarillo a rojo para identificar mejor visualmente los datos. Así como, el nombre de las escalas conforme a los indicadores.
ggplot(cat_indice_peligro) +
  geom_sf(aes(fill = IP_TorEle), color = NA) +
  scale_fill_fermenter(palette = "YlOrRd", direction = 1,  breaks = seq(min(0), max(1), length.out = 5), label = c("cero","1 a 9", "10 a 19", "20 a 29", ">30"))

  • Hice algunos ajustes adicionales para obtener el siguiente resultado:
ggplot(cat_indice_peligro) +
  geom_sf(aes(fill = IP_TorEle), color = NA) +
  scale_fill_fermenter(palette = "YlOrRd", direction = 1,  breaks = seq(min(0), max(1), length.out = 5), label = c("cero","1 a 9", "10 a 19", "20 a 29", ">30")) +
  labs(title = "Categorización del índice de peligro por tormentas eléctricas a nivel municipal",
       subtitle = "Datos del mapa del Nuevo Atlas de México (Vidal, 2007) con información de 1970 al 2002",
       caption = "CENAPRED, © Atlas Nacional de Riesgos",
       fill = "Días con tormenta") +
  theme_minimal()

  • Siguiendo los mismos paso podemos observar el indicador de Grado de riesgo por tormentas eléctricas.
grado_indice_peligro <- st_read("Grado de riesgo por tormentas electricas/TormElect_EscRiesgo.shp")
## Reading layer `TormElect_EscRiesgo' from data source 
##   `C:\Users\jmm_j\OneDrive\Documentos\AZUR\datos\azur\Grado de riesgo por tormentas electricas\TormElect_EscRiesgo.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 2456 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 907821.8 ymin: 319149.1 xmax: 4082997 ymax: 2349615
## Projected CRS: ITER92_CCL
  ggplot(grado_indice_peligro) +
  geom_sf(aes(fill = R_TORELE), color = NA) +
  scale_fill_jcolors_contin("pal3", reverse = TRUE) +
    labs(title = "Grado de riesgo por tormentas eléctricas",
       subtitle = "Datos del mapa del Nuevo Atlas de México (Vidal, 2007) con información de 1970 al 2002",
       caption = "CENAPRED, © Atlas Nacional de Riesgos",
       fill = "Grado") +
  theme_minimal()

  • Y podemos enfocar la atención en una entidad en específico. En este caso seguiremos con la Ciudad de México como ejemplo.
grado_indice_peligro_cdmx <- st_read("Grado de riesgo por tormentas electricas/TormElect_EscRiesgo.shp") %>%                              filter(CVE_ENT == "09")
## Reading layer `TormElect_EscRiesgo' from data source 
##   `C:\Users\jmm_j\OneDrive\Documentos\AZUR\datos\azur\Grado de riesgo por tormentas electricas\TormElect_EscRiesgo.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 2456 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 907821.8 ymin: 319149.1 xmax: 4082997 ymax: 2349615
## Projected CRS: ITER92_CCL
  ggplot(grado_indice_peligro_cdmx) +
  geom_sf(aes(fill = R_TORELE), color = "white", lwd = 0.1) +
  scale_fill_jcolors_contin("pal3", reverse = TRUE) +
    labs(title = "Grado de riesgo en la Ciudad de México",
       caption = "CENAPRED, © Atlas Nacional de Riesgos",
       fill = "Grado") +
  theme_minimal()

  • Éste último ejemplo es del Índice de peligro por tormentas eléctricas a nivel municipal.
indice_peligro_mun <- st_read("Indice de peligro por tormentas electricas a nivel municipal/Indice de peligro por tormentas electricas a nivel municipal.shp") %>% 
                      arrange(IP_TorEle)
## Reading layer `Indice de peligro por tormentas electricas a nivel municipal' from data source `C:\Users\jmm_j\OneDrive\Documentos\AZUR\datos\azur\Indice de peligro por tormentas electricas a nivel municipal\Indice de peligro por tormentas electricas a nivel municipal.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 2456 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 907821.8 ymin: 319149.1 xmax: 4082997 ymax: 2349615
## Projected CRS: North_America_Lambert_Conformal_Conic
  ggplot(indice_peligro_mun) +
  geom_sf(aes(fill = IP_TorEle), color = NA) +
  scale_fill_distiller(palette = "YlOrBr", direction = 1) +
  labs(title = "Índice de peligro por tormentas eléctricas a nivel municipal",
       subtitle = "Datos del mapa del Nuevo Atlas de México (Vidal, 2007) con información de 1970 al 2002",
       caption = "CENAPRED, © Atlas Nacional de Riesgos",
       fill = "Índice") +
  theme_minimal()