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
Para la elaboración del documento se utilizaron los mapas en diferentes escalas del Marco Geoestadístico del INEGI (link) en formato Shapefile (*.shp)
Así mismo, encontrará la elaboración de mapas hidrometeorológicos con Raw Data del Centro Nacional de Prevención de Desastres (CENAPRED) (link) en formato Shapefile (*.shp) con información perteneciente al Atlas Nacional de Riesgo.
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)
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.
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()
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="")
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()
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")
ggplot(cat_indice_peligro) +
geom_sf(aes(fill = IP_TorEle))
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"))
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()
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()
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()
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()