InformaciĂ³n de zonas metropolitanas https://www.gob.mx/conapo/documentos/las-metropolis-de-mexico-2020

https://www.gob.mx/cms/uploads/attachment/file/865680/Cuadros_MM2020.xlsx

Se identificaron 92 metrĂ³polis en el paĂ­s de tres tipos: 48 zonas metropolitanas, 22 metrĂ³polis municipales y 22 zonas conurbadas https://conapo.segob.gob.mx/work/models/CONAPO/Datos_Abiertos/DT/Metropolis.rar

Cuadros de la delimitaciĂ³n de las metrĂ³polis de MĂ©xico 2020

Contexto geogrĂ¡fico

https://inegi.org.mx/contenidos/productos/prod_serv/contenidos/espanol/bvinegi/productos/geografia/marcogeo/794551132173_s.zip

library(rnaturalearth)
target <- c("Mexico")
sf::sf_use_s2(FALSE) 

countries<- ne_countries(scale = 10,returnclass = 'sf') %>%
  filter(name %in% target)

countries<-st_transform(countries, CRS("+init=epsg:4326 +proj=longlat
+                                     +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"))
polygon = st_cast(countries, "POLYGON", do_split = FALSE) 
mex<-polygon$geometry
#plot(mex)



ruta<-"C:/Users/cguer/Documents/Claudia/Midropbox/Investigacion y escritos/karamanis/data/Metropolis/"
infile <- "Metropolis_2020.shp"
nomarchi<-as.filename(paste0(ruta,infile))
datageomet<- read_sf(nomarchi,options = "ENCODING=UTF8")
datageomet= st_transform(datageomet, crs = 4326)

ruta<-"C:/Users/cguer/Documents/Claudia/Midropbox/Investigacion y escritos/karamanis/portraits/torreon/"
infile <- "metropolis"
datacom <- read.csv(paste0(ruta,infile,'.csv'),encoding = "UTF-8")

datageomet2<-merge(datageomet,datacom, by.x = "CVE_MET", by.y = "Clave.de.metrĂ³poli", all.x = TRUE)
ruta<-"C:/Users/cguer/Documents/Claudia/Midropbox/Investigacion y escritos/karamanis/portraits/torreon/"
infile <- "metropolisdatmun"
datacommun <- read.csv(paste0(ruta,infile,'.csv'),encoding = "UTF-8")



# Se convierte en un dato alfanumérico de dos digito como "01", "02",..."32"

codent<-substr(datacommun$Clave.de.la.entidad,1,2)
codent<-sprintf("%02d%s", as.numeric(gsub("[^0-9]+", "", codent)), gsub("[0-9]+", "", codent))
codmun<-substr(datacommun$Clave.de.municipio,1,3)
codmun<-sprintf("%03d%s", as.numeric(gsub("[^0-9]+", "", codmun)), gsub("[0-9]+", "", codmun))
cvegeo<-paste0(codent,codmun)
datacommun$CVEGEO<-cvegeo



#datageomet<-merge(datageomet,datacom, by.x = "CVE_MET", by.y = "Clave.de.metrĂ³poli", all.x = TRUE)
datageomet<-merge(datageomet,datacommun, by.x = "CVEGEO", by.y = "CVEGEO", all.x = TRUE)

breaks2 <- classInt::classIntervals(
  datageomet$Densidad.media.urbana,
  n = 9,
  style = "equal",
  intervalClosure="right"
)$brks


g <- ggplot() +
  geom_sf(data = mex, fill = NA) +
   geom_sf(data = datageomet, aes(fill = TIPO_MET),alpha=.7) +
  scale_fill_manual(values = c("#f94144",
                               "#277da1",
                               "#f9a64f",
                               "#90be6d",
                               "#277da1",
                               "#f9a64f",
                               "#277da1",
                               "#9000ab",
                               "#277da1",
                               "#277da1",
                               "#f9a64f",
                               "#90beee",
                               "#577590",
                               "#f1345b",
                               "#19456c",
                               "#10028a",
                               "#24528a"))+

  labs(
    title = "MetrĂ³polis en MĂ©xico"
  ) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    plot.title = element_text(size = 30)
  )
g

metrop<-"Ocotlcn"
metrop<-"Irapuato"
metrop<-"Guadalajara"
metrop<-"Monterrey"
metrop<-"La Laguna"

datageomet<- datageomet|> filter(NOM_MET %in% c(metrop))

titulo<-paste0("Municipios de ",datageomet$NOM_MET)

g <- ggplot() +
   geom_sf(data = datageomet, aes(fill = NOMGEO),alpha=.7) +
  scale_fill_manual(values = c("#f94144",
                               "#277da1",
                               "#f9a64f",
                               "#90be6d",
                               "#277da1",
                               "#f9a64f",
                               "#277da1",
                               "#9000ab",
                               "#277da1",
                               "#277da1",
                               "#f9a64f",
                               "#90beee",
                               "#577590",
                               "#f1345b",
                               "#19456c",
                               "#10028a",
                               "#24528a"))+

  labs(
    title = titulo
  ) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    plot.title = element_text(size = 30)
  )
g

    datageo_geom <- st_geometry(datageomet)
polygon = st_cast(datageo_geom, "POLYGON") 
    #   plot(polygon)


b<- st_union(polygon)
#plot(b)
c<-st_polygon(b[[1]]) 
ext_ring <- st_polygon(b[[1]][1]) 
#plot(ext_ring)

RecuperaciĂ³n de archivo de asentamientos en el INEGI Asentamientos humanos INEGI

Colonias https://www.inegi.org.mx/programas/dcah/

ruta<-"C:/Users/cguer/Documents/Claudia/Midropbox/Investigacion y escritos/karamanis/data/conjunto_de_datos/"
infile <- "00as.shp"
nomarchi<-as.filename(paste0(ruta,infile))
nomfil<-"00as"


#a<-"SELECT * FROM \"00as\" WHERE (CVE_ENT = '05' OR CVE_ENT = '10') AND (CVE_MUN='035' OR CVE_MUN ='007' OR CVE_MUN='012')"
#a<-"SELECT * FROM \"00as\" WHERE (CVE_ENT = '05' AND CVE_MUN = '035') OR (CVE_ENT='05' AND CVE_MUN ='017') OR (CVE_ENT='10' AND CVE_MUN ='007') OR (CVE_ENT='10' AND CVE_MUN='012')"
a<-"SELECT * FROM \"00as\" WHERE (CVE_ENT = '11' AND CVE_MUN = '015')"
`%notin%` <- Negate(`%in%`)

#datageot<- read_sf(nomarchi,options = "ENCODING=latin1",query=a)
datageot<- read_sf(nomarchi,options = "ENCODING=latin1")
datageot= st_transform(datageot, crs = 4326)
#unique(datageot$TIPO)


    datageot<- datageot|> filter(TIPO %notin% c("NINGUNO","CIUDAD"))

    compa<-unique(datageomet$TIPO_MET)
 if (compa == "MetrĂ³poli municipal") {
        datageot<- datageot|> filter(CVE_ENT %in% c(datageomet$CVE_ENT)) |> filter(CVE_MUN %in% c(datageomet$CVE_MUN))
    } else {
        datageot<-datageot[ext_ring, ]
    }

    



titulo<-paste0("Asentamientos humanos en ",datageomet$NOM_MET)
g <- ggplot() +
  #geom_sf(data = tor, fill = NA) +
  geom_sf(data = datageomet, aes(fill = NOMGEO),alpha=.7) +
 
  scale_fill_manual(values = c("#f94144",
                               "#277da1",
                               "#f9a64f",
                               "#90be6d",
                               "#277da1",
                               "#f9a64f",
                               "#277da1",
                               "#9000ab",
                               "#277da1",
                               "#277da1",
                               "#f9a64f",
                               "#90beee",
                               "#577590",
                               "#f1345b",
                               "#19456c",
                               "#10028a",
                               "#24528a"))+
                              

  geom_sf(data = datageot, fill = "grey",alpha=.7) +
  labs(
    title = titulo) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    legend.position = "bottom",
    legend.key.width = unit(3, "line"),
    legend.key.height = unit(0.5, "line"),
    plot.background = element_rect(fill = NA, color = NA),
    plot.title = element_text(size = 20,  hjust = 0.5, face = "bold"),
    plot.subtitle = element_text(size = 16,  hjust = 0.5),
    plot.caption = element_text(size = 10,  hjust = 0.5, margin = margin(20, 0, 0, 0))
    
  )


g

lim<-st_bbox(datageomet)
#lim$ymax<-25.65
q <- opq(bbox = c(lim$xmin, lim$ymin, lim$xmax, lim$ymax))%>% 
  add_osm_feature(key = "highway") %>% 
  osmdata_sf()
qosm_sf <- q$osm_lines 
st_crs(qosm_sf) <-4326


qosm_sf <- qosm_sf|> filter(highway %in% c("primary","secondary","tertiary"))


#plot(qosm_sf$geometry)




xlim <- c(lim$xmin,lim$xmax)
ylim <- c(lim$ymin,lim$ymax)
titulo<-paste0("Zona metropolitana de ",datageomet$NOM_MET)
g <- ggplot() +
    geom_sf(data = datageomet, aes(fill = NOMGEO),alpha=.7) +

 # geom_sf(data = recorteosmlayer4, fill = NA,alpha=0.1,linewidth=0.05,color="grey") +
    #geom_sf(data = datageot, fill=NA,color="navy",linewidth = 0.5) +
      geom_sf(data = qosm_sf, color="navy",fill = NA, linewidth = 0.1) +


  labs(
    title = titulo
  ) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    plot.title = element_text(size = 15)
  )+
  coord_sf(xlim = xlim, ylim = ylim)

g

pal <- MetBrewer::met.brewer("Johnson")
datageomet$Pobla<-as.numeric(gsub(" ","",datageomet$PoblaciĂ³n.2020))

#datageomet<- datageomet|> filter(NOM_MET %in% c("Saltillo"))

minipob<-min(datageomet$Pobla)
maxpob<-max(datageomet$Pobla)

g <- ggplot() +
    geom_sf(data = datageomet, aes(fill = Pobla,alpha=.7))+
    scale_fill_gradientn(colors = pal, na.value = "white", breaks = seq(minipob, maxpob, 150000), limits = c(minipob, maxpob)) +
       
  #geom_sf(data = qosm_sf, color="navy",fill = NA, linewidth = 0.1) +
  labs(
    title = titulo
  ) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    plot.title = element_text(size = 15)
  )+
  coord_sf(xlim = xlim, ylim = ylim)

g

library(cptcity)
#http://soliton.vm.bytemark.co.uk/pub/cpt-city/notes/formats.html
#http://soliton.vm.bytemark.co.uk/pub/cpt-city/index.html
pals <- find_cpt("blues")
pals <- find_cpt("population")
pals <- find_cpt("cmocean")

#names(basemapa2)[17] ="POBTOTMENOR25000"


library(RColorBrewer)



g <- ggplot() +
    geom_sf(data = datageomet, aes(fill = Pobla))+
    #scale_fill_gradientn(colors = pal, na.value = "white", breaks = seq(minipob, maxpob, 150000), limits = c(minipob, maxpob)) +
  scale_fill_gradientn(name="PoblaciĂ³n",colours=brewer.pal(6,"PuBu"))+

  geom_sf(data = qosm_sf, color="navy",fill = NA, linewidth = 0.1) +
  labs(
    title = titulo
  ) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    plot.title = element_text(size = 15)
  )+
  coord_sf(xlim = xlim, ylim = ylim)

g

Densidad media urbana

Consiste en la concentraciĂ³ y dispersiĂ³n poblacional de una determinada Ă¡rea geogrĂ¡fica y se calcula como nĂºmero de habitantes por unidad de superficie, (habitantes por hectĂ¡rea), permite comparar la ocupaciĂ³n territorial entre las metrĂ³polis y el cĂ¡lculo sĂ³lo incorpora la porciĂ³n del territorio clasificado cmo urbano o rural

Para su cĂ¡lculo se utilizĂ³ como dato de superficie el de las Ă¡reas geoestadĂ­sticas bĂ¡sicas urbanas del Marco GeoestadĂ­sitico,

numunip<-nrow(datageomet)
if(numunip > 1) {
  breaks2 <- classInt::classIntervals(
  datageomet$Densidad.media.urbana,
  n = numunip,
  style = "quantile"
)$brks
} else {
  breaks2 <-1
}



datacol <-datageomet %>% 
  mutate(centroids = st_centroid(st_geometry(.)))
nc3_coords <- as.data.frame(sf::st_coordinates(datacol$centroids))
nc3_coords$nombre <- datacol$NOMGEO



g <- ggplot() +
    geom_sf(data = datageomet, aes(fill = Densidad.media.urbana))+
    #scale_fill_gradientn(colors = pal, na.value = "white", breaks = seq(minipob, maxpob, 150000), limits = c(minipob, maxpob)) +
  #scale_fill_gradientn(colours=brewer.pal(6,"PuBu"))+
  scale_fill_gradientn(name="densidad media",colours = cpt(n = numunip, "cmocean_matter"),breaks = round(breaks2, 0))+

  geom_sf(data = qosm_sf, color="navy",fill = NA, linewidth = 0.1) +
    geom_text(data = nc3_coords, aes(X, Y-.07, label = nombre), colour = "black",size = 5,check_overlap = TRUE)+

  labs(
    title = titulo
  ) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    plot.title = element_text(size = 15),
      legend.position="bottom",
      legend.key.width = unit(4, "cm"),
      axis.line = element_blank(),
      axis.text.x = element_blank(),
      axis.text.y = element_blank(),
      axis.ticks = element_blank(),
      axis.title.x = element_blank(),
      axis.title.y = element_blank(),
    panel.grid.minor = element_blank(),
      plot.background = element_rect(fill = "transparent", color = "transparent"), 
      # panel.background = element_rect(fill = "transparent", color = "transparent"), 
      panel.background = element_blank(),
      legend.background = element_rect(fill = "transparent", color = "transparent"),
      panel.border = element_blank(),
    
      legend.direction="horizontal"
  )+
  coord_sf(xlim = xlim, ylim = ylim)

g

bottom  =as.numeric(round(lim$ymin,digits=2))
top     = as.numeric(round(lim$ymax,digits=2))
left    = as.numeric(round(lim$xmin,digits=2))
right   = as.numeric(round(lim$xmax,digits=2))
borders<-c(left,bottom,right,top)

#map<-get_stadiamap(borders, zoom = 12, maptype = "stamen_terrain_background")
map<-get_stadiamap(borders, zoom = 12, maptype = "stamen_terrain")


ggmap(map)+
    geom_text(data = nc3_coords, aes(X, Y-.07, label = nombre), colour = "black",size = 5,check_overlap = TRUE)+
    geom_sf(data = qosm_sf, color="navy",fill = NA, linewidth = 0.1,inherit.aes = FALSE)+
    geom_sf(data = datageomet, inherit.aes = FALSE,fill="transparent",color="black",linewidth=1)+
  labs(
    title = titulo
  ) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    plot.title = element_text(size = 15),
      legend.position="bottom",
      legend.key.width = unit(4, "cm"),
      axis.line = element_blank(),
      axis.text.x = element_blank(),
      axis.text.y = element_blank(),
      axis.ticks = element_blank(),
      axis.title.x = element_blank(),
      axis.title.y = element_blank(),
    panel.grid.minor = element_blank(),
      plot.background = element_rect(fill = "transparent", color = "transparent"), 
      # panel.background = element_rect(fill = "transparent", color = "transparent"), 
      panel.background = element_blank(),
      legend.background = element_rect(fill = "transparent", color = "transparent"),
      panel.border = element_blank(),
    
      legend.direction="horizontal"
  )

ggmap(map)+
    geom_text(data = nc3_coords, aes(X, Y-.07, label = nombre), colour = "black",size = 5,check_overlap = TRUE)+
    geom_sf(data = datageot, inherit.aes = FALSE,fill="grey",color="navyblue",linewidth=.2) +
    geom_sf(data = datageomet, inherit.aes = FALSE,fill="transparent",color="black",linewidth=1)+
  labs(
    title = titulo
  ) +
  theme_minimal(
    base_family = "body_font",
    base_line_size = unit(0.1, "mm")
  ) +
  theme(
    plot.title = element_text(size = 15),
      legend.position="bottom",
      legend.key.width = unit(4, "cm"),
      axis.line = element_blank(),
      axis.text.x = element_blank(),
      axis.text.y = element_blank(),
      axis.ticks = element_blank(),
      axis.title.x = element_blank(),
      axis.title.y = element_blank(),
    panel.grid.minor = element_blank(),
      plot.background = element_rect(fill = "transparent", color = "transparent"), 
      # panel.background = element_rect(fill = "transparent", color = "transparent"), 
      panel.background = element_blank(),
      legend.background = element_rect(fill = "transparent", color = "transparent"),
      panel.border = element_blank(),
    
      legend.direction="horizontal"
  )