R2

Author

RMMD

Importations librerias y datos

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.3.3
Warning: package 'tibble' was built under R version 4.3.1
Warning: package 'tidyr' was built under R version 4.3.1
Warning: package 'readr' was built under R version 4.3.1
Warning: package 'purrr' was built under R version 4.3.1
Warning: package 'dplyr' was built under R version 4.3.1
Warning: package 'stringr' was built under R version 4.3.3
Warning: package 'forcats' was built under R version 4.3.1
Warning: package 'lubridate' was built under R version 4.3.1
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(leaflet)
Warning: package 'leaflet' was built under R version 4.3.1
# Importamos shapes
shp_secc_sonora <- sf::st_read('www/Sonora/shp/Seccion.shp') %>% 
  sf::st_transform(4326)
Reading layer `Seccion' from data source 
  `C:\Users\ricar\Documents\Proyectos\Análisis político electoral\QUIPU\tratamiento_secciones\www\Sonora\shp\Seccion.shp' 
  using driver `ESRI Shapefile'
Simple feature collection with 1528 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 118332.3 ymin: 2910645 xmax: 752812.4 ymax: 3601534
Projected CRS: WGS 84 / UTM zone 12N
shp_mx <- sf::st_read('www/shp/00mun2.shp') %>% 
  sf::st_transform(4326)
Reading layer `00mun2' from data source 
  `C:\Users\ricar\Documents\Proyectos\Análisis político electoral\QUIPU\tratamiento_secciones\www\shp\00mun2.shp' 
  using driver `ESRI Shapefile'
Simple feature collection with 2469 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 911292 ymin: 319149.1 xmax: 4082997 ymax: 2349615
Projected CRS: MEXICO_ITRF_2008_LCC
shp_sono <- shp_mx[shp_mx$CVE_ENT == "26" ,]
datos_ganadores_SONORA <- readr::read_csv("www/Sonora/data/datos_ganadores_SONORA.csv")
Rows: 1483 Columns: 15
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (13): gober_15, alcalde_15, dip_local_15, dip_fed_15, dip_local_18, sena...
dbl  (2): poblacion, seccion

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
shp_secc_sonora_faltantes = shp_secc_sonora[!(shp_secc_sonora$SECCION %in% 
                                                unique(datos_ganadores_SONORA$seccion)),]
bounds <- shp_secc_sonora %>% sf::st_bbox() %>% as.character()

leaflet() %>%
    addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  fitBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
  addPolygons(data = shp_sono, 
              label = paste0(shp_sono$CVE_MUN," - ",shp_sono$NOMGEO),
              fillOpacity = 0.4,
              fillColor = '#ffffff',
              weight = 1, 
              color = '#3a0ca3',
              opacity = 1,
              smoothFactor = 1) %>% 
  addPolygons(data = shp_secc_sonora_faltantes, 
              label = paste0(shp_secc_sonora_faltantes$MUNICIPIO," - ",
                             shp_secc_sonora_faltantes$SECCION), 
              #layerId = ~NOMGEO,
              fillOpacity = 1, 
              fillColor = '#9C0D38', 
              weight = 1.5, 
              color = '#9C0D38',
              opacity = 1.0, 
              smoothFactor = 0.5)