library(rgdal)
library(readxl)
library(RColorBrewer)
library(leaflet)
library(dplyr)
library(htmltools)
mapa_mexico<-readOGR("C:\\Users\\permi\\Desktop\\CIDE\\Primer semestre\\R\\Mexico\\conjunto_de_datos",layer = "mexico_32")
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\permi\Desktop\CIDE\Primer semestre\R\Mexico\conjunto_de_datos", layer: "mexico_32"
## with 32 features
## It has 2 fields
mexico<-read_excel("C:\\Users\\permi\\Desktop\\CIDE\\Primer semestre\\R\\Mexico\\mg_sep2019_integrado\\mexico.xlsx")
- (10%) Considerando la división (cut) por cuantiles, representar en un mapa el porcentaje de población que muestra rezago educativo
mexico_re<-mexico[,c(2,5)]
tabla33<-merge(x=mapa_mexico@data, y=mexico_re, by.x="CVE_ENT", by.y="Clave de entidad", sort=FALSE )
mapa_mexico@data$mex_re<-tabla33$`Rezago educativo`
my_colors_re<-brewer.pal(5,"Reds")
my_colors_re<-colorRampPalette(my_colors_re)(4)
cuantil_re<-cut(mapa_mexico@data$mex_re ,4)
my_colors_re<-my_colors_re[as.numeric(cuantil_re)]
#Levels: (9.49,15.3] (15.3,21] (21,26.8] (26.8,32.5]
cortess <- c(9.49,15.3,21,26.8,Inf)
colores <- colorBin( palette="Reds", domain=mapa_mexico$mex_re ,na.color="transparent", bins=cortess)
textoss <- paste(
"Estado : ",mapa_mexico$NOM_ENT ,"<br/>",
"% de población que muestra rezago educativo: ", round(mapa_mexico$mex_re ,2),"<br/>" ) %>% lapply(htmltools::HTML)
leaflet(data=mapa_mexico ) %>%
addTiles() %>%
addPolygons(label = textoss,fillColor = colores(mapa_mexico$mex_re),
fillOpacity = 0.9) %>%
addLegend("topleft", colors = c("#FEE5D9", "#FB9779", "#E74132", "#A50F15"),
labels= c("(9.49%-15.3%)","(15.3%-21%)","(21%-26.8%)","(26.8%-32.5%)"),
title= "Porcentaje de poblacion que muestra rezago educativo.", opacity = 0.9)