setwd("C:/Users/frank/Desktop")
library(readxl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(rgdal)
## Loading required package: sp
## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/frank/Documents/R/win-library/4.1/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/frank/Documents/R/win-library/4.1/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/frank/Documents/R/win-library/4.1/rgdal/proj
library(rgeos)
## rgeos version: 0.5-5, (SVN revision 640)
## GEOS runtime version: 3.8.0-CAPI-1.13.1
## Linking to sp version: 1.4-5
## Polygon checking: TRUE
library(maptools)
## Checking rgeos availability: TRUE
library(ggplot2)
library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
list.files()
## [1] "~$allpa_Tesis2.docx"
## [2] "~$allpa_TesisAvance2.docx"
## [3] "~$allpaFrank_Tesis PRIMER CAPITULO.docx"
## [4] "~$allpaFrank_Tesis PRIMER CAPITULO_OBSERVACIONES.docx"
## [5] "~WRL0005.tmp"
## [6] "~WRL0006.tmp"
## [7] "1-Link_Geoportales de Perú.pdf"
## [8] "Capitulo 1"
## [9] "Capitulo 2"
## [10] "codigomapas.R"
## [11] "ComitesUPP.html"
## [12] "ComitesUPP.nb.html"
## [13] "ComitesUPP.Rmd"
## [14] "Diseño Investigación-x"
## [15] "ELECCIONES2006.xlsx"
## [16] "Entregas"
## [17] "Entrevistas"
## [18] "Huallpa_TesisAvance2.docx"
## [19] "Limite_departamental.rar"
## [20] "Limite_provincial.rar"
## [21] "MapaElecciones2006.nb.html"
## [22] "MapaElecciones2006.Rmd"
## [23] "MapaElecciones2011.nb.html"
## [24] "MapaElecciones2011.Rmd"
## [25] "Provincias2011.xlsx"
## [26] "rsconnect"
## [27] "Seminario 1-x"
## [28] "SEMINARIO 2"
Abrimos el archivo
provincias <- st_read("C:/Users/frank/Desktop/PROVINCIAS/BAS_LIM_PROVINCIA.shp")
## Reading layer `BAS_LIM_PROVINCIA' from data source `C:\Users\frank\Desktop\PROVINCIAS\BAS_LIM_PROVINCIA.shp' using driver `ESRI Shapefile'
## Simple feature collection with 197 features and 10 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -203260.8 ymin: 7964769 xmax: 1190991 ymax: 9995733
## Projected CRS: WGS 84 / UTM zone 18S
plot(st_geometry(provincias))
Exportation la data
setwd("C:/Users/frank/Desktop/TESIS")
elecciones2006 <- read_excel("ELECCIONES2006.xlsx")
Merge
ProvinciasMapa <- merge(provincias,elecciones2006, by.x = "NOMBPROV", by.y="PROVINCIA")
Creamos Mapa
Mapa <- ggplot(data = ProvinciasMapa) +
geom_sf(aes(fill=`VOTOS VALIDOS` ), data = ProvinciasMapa, color='black', size=0.3) +
guides(fill=guide_colorbar(title = "% votos validos (UPP)")) +
scale_fill_gradient(limits= c(0,100), high = "red", low = "white", guide = "colorbar") +
ggtitle("Resultados Primera Vuelta 2006")+
theme_bw()+
theme(
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
Mapa