Diego Arturo Gonzalez Delgadillo 20 de Mayo
La cartografia tematica es una herramienta util para plasmar variables estadisticas, geografoas economicas, etc, las cuales se pueden evaluar, nterpretar y utilizar de una manera mas eficiente y sencilla. En este informe se plasmaran diferentes tipos de mapas tematicos correspondientes a los niveles de NBI y de produccion de platano en el departamento de Arauca, con el objetivo de poner en practica las herramientas y paquetes cartograficos de R, asi como la de conocer la realidad socieconomica del departamento.
Se comienza limpieando la memoria.
rm(list=ls())
Se instalan los paquetes necesarios para la realizacion de mapas tematicos.
list.of.packages <- c("tidyverse", "rgeos", "sf", "raster", "cartography", "SpatialPosition")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
Se cargan los paquetes.
library(tidyverse)
library(readxl)
library(rgeos)
library(raster)
library(sf)
library(cartography)
library(SpatialPosition)
Se leen los datos NBI adaptados previamente para el departamento de Arauca.
NBI <- read_excel("C:/Users/Lina Maria Ayala.LinaMariaAyala/Documents/R/TRABAJOS GEOMATICA/ARAUCA/NBI_2018_ARAUCA.xlsx")
Los atributos de los datos son los siguientes:
head(NBI)
Se filtran los datos para saber cual es la poblacion con mayor NBI.
NBI %>%
slice(which.max(NBI)) -> MAX_NBI
MAX_NBI
Se filtran los datos para saber cual es la poblacion con menor NBI.
NBI %>%
slice(which.min(NBI)) -> MIN_NBI
MIN_NBI
Se ordenal los municipios por NBI de forma descendiente.
NBI %>%
arrange(desc(NBI)) -> DESC_NBI
DESC_NBI
Para hacer el empalme de los datos NBI con los datos administrativos del departamento de arauca se deben leer primero estos ultimos datos.
MUNIC <- st_read("C:/Users/Lina Maria Ayala.LinaMariaAyala/Documents/R/TRABAJOS GEOMATICA/ARAUCA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp")
Reading layer `MGN_MPIO_POLITICO' from data source `C:\Users\Lina Maria Ayala.LinaMariaAyala\Documents\R\TRABAJOS GEOMATICA\ARAUCA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp' using driver `ESRI Shapefile'
Simple feature collection with 7 features and 9 fields
geometry type: POLYGON
dimension: XY
bbox: xmin: -72.36662 ymin: 6.036228 xmax: -69.42756 ymax: 7.104381
CRS: 4326
Los atributos de MPIO_CCDGO son:
head(MUNIC$MPIO_CNMBR)
[1] ARAUCA PUERTO RONDÓN CRAVO NORTE ARAUQUITA FORTUL
[6] SARAVENA
Levels: ARAUCA ARAUQUITA CRAVO NORTE FORTUL PUERTO RONDÓN SARAVENA TAME
Se hace ahora el empalme.
NBI_MUNIC = left_join(MUNIC, NBI, by=c("MPIO_CCDGO"="CODIGO"))
NBI_MUNIC %>%
dplyr::select(MUNICIPIO, MPIO_CCDGO, NBI) -> CHECK_NBI_MUNIC
head(CHECK_NBI_MUNIC)
Simple feature collection with 6 features and 3 fields
geometry type: POLYGON
dimension: XY
bbox: xmin: -72.12902 ymin: 6.036228 xmax: -69.42756 ymax: 7.104381
CRS: 4326
MUNICIPIO MPIO_CCDGO NBI geometry
1 ARAUCA 81001 31.31959 POLYGON ((-70.68038 7.09393...
2 PUERTO RONDÓN 81591 22.77443 POLYGON ((-70.87879 6.62133...
3 CRAVO NORTE 81220 29.61032 POLYGON ((-70.40276 6.64639...
4 ARAUQUITA 81065 41.38370 POLYGON ((-71.58441 7.04298...
5 FORTUL 81300 34.35667 POLYGON ((-71.54473 6.75924...
6 SARAVENA 81736 27.70381 POLYGON ((-71.76224 7.06602...
Se reproyectan los municipios.
NBI_MUNIC_NUEVO <- st_transform(NBI_MUNIC, crs = 3116)
MAPAS TEMATICOS
Mapa base de OpenStreetMap y sÃmbolos proporcionales.
En primer lugar se hara un mapa tematico usando el paquete cartografico que represente los niveles de NBI por cad municipio por medio depuntos o simbolos.
MUN.OSM <- getTiles(
x = NBI_MUNIC_NUEVO,
type = "OpenStreetMap",
zoom = 8,
cachedir = TRUE,
crop = FALSE
)
Se establecen las margenes, los limites municipales, color, diseño la flecha que indica el norte.
opar <- par(mar = c(0,0,1.2,0))
tilesLayer(x = MUN.OSM)
plot(st_geometry(NBI_MUNIC_NUEVO), col = NA, border = "darkred", add=TRUE)
propSymbolsLayer(
x = NBI_MUNIC_NUEVO,
var = "NBI",
inches = 0.2,
col = "darkorange2",
legend.pos = "topright",
legend.title.txt = "Total NBI")
layoutLayer(title = "DISTRIBUCION NBI EN ARAUCA",
sources = "Fuente: DANE, 2018\n© OpenStreetMap",
author = "Diego Arturo Gonzalez Delgadillo",
frame = TRUE, north = FALSE, tabtitle = TRUE)
north(pos = "topleft")
Mapas Choropleth
En los mapas coropléticos, las áreas se sombrean de acuerdo con la variación de una variable cuantitativa. Se usan para representar razones o Ãndices.
Se establecen las margenes,color de fondo,limites municipales,diseño y felcha indicativa del norte.
opar <- par(mar = c(0,0,1.2,0))
par(bg="grey98")
plot(st_geometry(NBI_MUNIC_NUEVO), col = NA, border = NA, bg = "#C6C638")
choroLayer(
x = NBI_MUNIC_NUEVO,
var = "NBI",
method = "geom",
nclass=5,
col = carto.pal(pal1 = "blue.pal", n1 = 5),
border = "white",
lwd = 0.5,
legend.pos = "topright",
legend.title.txt = "NBI",
add = TRUE
)
layoutLayer(title = "DISTRIBUCION NBI EN ARAUCA",
sources = "Fuente: DANE, 2018",
author = "Diego Arturo Gonzalez Delgadillo",
frame = TRUE, north = TRUE, tabtitle = TRUE, col="black")
north(pos = "topleft")
SÃmbolos proporcionales y mapa de tipologÃa
Este mapa se crean simnolos proporcionales al tamaño de una variables en zonas especificas. En primer lugar se deb crear una variable cuantutativa con los datos que ya se tenian.
NBI_MUNIC_NUEVO2<- dplyr::mutate(NBI_MUNIC_NUEVO, Pobreza = ifelse(MISERIA > 10, "Extreme",
ifelse(HACINAMIENTO >8,"High", "Intermediate")))
Estos son los nuevos atributos:
head(NBI_MUNIC_NUEVO2)
Simple feature collection with 6 features and 21 fields
geometry type: POLYGON
dimension: XY
bbox: xmin: 1215550 ymin: 1161263 xmax: 1515269 ymax: 1278742
CRS: EPSG:3116
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC
1 81 81001 ARAUCA 1959
2 81 81591 PUERTO RONDÓN Decreto Nal 677 de Abril 13 de 1987
3 81 81220 CRAVO NORTE Decreto Nal 677 de Abril 13 de 1987
4 81 81065 ARAUQUITA Decreto 1447 del 28 de Julio de 1971
5 81 81300 FORTUL Decreto 2926 de 1989
6 81 81736 SARAVENA Decreto Nal 204 de Feb 3 de 1976
MPIO_NAREA MPIO_NANO DPTO_CNMBR Shape_Leng Shape_Area COD_DEPTO DEPTO COD_MUN
1 5787.9421 2017 ARAUCA 4.668016 0.47162612 81 ARAUCA 001
2 2281.4291 2017 ARAUCA 2.932376 0.18593602 81 ARAUCA 591
3 5212.6908 2017 ARAUCA 3.963937 0.42393331 81 ARAUCA 220
4 3046.8789 2017 ARAUCA 3.258765 0.24864660 81 ARAUCA 065
5 1158.6276 2017 ARAUCA 2.056433 0.09461063 81 ARAUCA 300
6 945.1354 2017 ARAUCA 1.294126 0.07721413 81 ARAUCA 736
MUNICIPIO NBI MISERIA VIVIENDA SERVICIOS HACINAMIENTO INASISTENCIA
1 ARAUCA 31.31959 9.524767 23.55534 2.840414 9.164355 2.342002
2 PUERTO RONDÓN 22.77443 7.406514 12.42461 1.013269 7.696019 4.511460
3 CRAVO NORTE 29.61032 8.726674 16.10867 2.661910 8.616905 2.661910
4 ARAUQUITA 41.38370 10.664613 33.61016 2.495926 7.563682 2.824102
5 FORTUL 34.35667 10.451880 24.40497 4.553294 9.060596 2.385880
6 SARAVENA 27.70381 7.932591 20.45794 2.582348 7.748957 2.515398
ECONOMICA geometry Pobreza
1 5.690207 POLYGON ((1375506 1277590, ... High
2 7.985525 POLYGON ((1353901 1225089, ... Intermediate
3 10.592755 POLYGON ((1406614 1228231, ... High
4 8.773692 POLYGON ((1275536 1271316, ... Extreme
5 9.457284 POLYGON ((1280090 1239930, ... Extreme
6 5.866713 POLYGON ((1255857 1273763, ... Intermediate
Se establecen las margenes,color de fondo,limites municipales,diseño y felcha indicativa del norte.
library(sf)
library(cartography)
opar <- par(mar = c(0,0,1.2,0))
plot(st_geometry(NBI_MUNIC_NUEVO2), col="#99ff99", border="#5454AA", bg = "#FFFF00",
lwd = 0.5)
propSymbolsTypoLayer(
x = NBI_MUNIC_NUEVO2,
var = "NBI",
inches = 0.35,
symbols = "square",
border = "white",
lwd = .5,
legend.var.pos = c(100000, 14100000),
legend.var.title.txt = "NBI",
var2 = "Pobreza",
legend.var2.values.order = c("Extreme", "High",
"Intermediate"),
col = carto.pal(pal1 = "harmo.pal", n1 = 3),
legend.var2.pos = c(100000, 14100000),
legend.var2.title.txt = "Pobreza"
)
layoutLayer(title="DISTRIBUCION NBI EN ARAUCA",
author = "Diego Arturo Gonzalez Delgadillo",
sources = "Fuente: DANE, 2018",
scale = 1, tabtitle = TRUE, frame = TRUE)
north(pos = "topleft")
Mapas con etiquetas
En este tipo de mapas se intenta combinar nombres con variables. Se establecen las margenes,color de fondo,limites municipales,diseño y felcha indicativa del norte.
library(sf)
library(cartography)
opar <- par(mar = c(0,0,1.2,0))
par(bg="grey25")
plot(st_geometry(NBI_MUNIC_NUEVO2), col = "#99ff99", border = "grey",
bg = "deepskyblue3", lwd = 0.5)
choroLayer(
x = NBI_MUNIC_NUEVO,
var = "NBI",
method = "geom",
nclass=5,
col = carto.pal(pal1 = "red.pal", n1 = 5),
border = "white",
lwd = 0.5,
legend.pos = "topright",
legend.title.txt = "NBI",
add = TRUE
)
labelLayer(
x = NBI_MUNIC_NUEVO2,
txt = "MUNICIPIO",
col= "white",
cex = 0.7,
font = 4,
halo = TRUE,
bg = "grey25",
r = 0.1,
overlap = FALSE,
show.lines = FALSE
)
layoutLayer(
title = "MUNICIPIO DE ARAUCA Y SUS NIVELES DE NBI",
sources = "FUENTE: DANE, 2018",
author = "Diego Arturo Gonzalez Delgadillo",
frame = TRUE,
north = TRUE,
tabtitle = TRUE,
theme = "red.pal"
)
Mapas Isopleth
Estos mapas se basan en variables de distribucion continua en un area determinada, para ello entonces en este caso integraremos los datos de produccion de platano en Arauca con el paquete cartorafico.
Se leen primeros los datos productivos.
CULTIVOS2018 <- read_excel("C:/Users/Lina Maria Ayala.LinaMariaAyala/Documents/R/TRABAJOS GEOMATICA/ARAUCA/Evaluaciones_Agropecuarias_Municipales_EVA 2.xlsx")
Estos son los atributos.
head(CULTIVOS2018)
Se filtran los datos por correspondientes al cultivo de platano.
CULTIVOS2018 %>%
filter(CULTIVO == "PLATANO") -> PLATANO2018
Se crea un nuevo atributo que coincida con los codigos del municipio.
PLATANO2018$TEMP <- as.character(PLATANO2018$COD_MUN)
PLATANO2018$MPIO_CCDGO <- as.factor(PLATANO2018$TEMP)
Se hace ahora la union.
PLATANO_MUNIC = left_join(MUNIC, PLATANO2018, by="MPIO_CCDGO")
Se verifican los atributos de salida.
head(PLATANO_MUNIC)
Simple feature collection with 6 features and 25 fields
geometry type: POLYGON
dimension: XY
bbox: xmin: -72.12902 ymin: 6.036228 xmax: -69.42756 ymax: 7.104381
CRS: 4326
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC
1 81 81001 ARAUCA 1959
2 81 81591 PUERTO RONDÓN Decreto Nal 677 de Abril 13 de 1987
3 81 81220 CRAVO NORTE Decreto Nal 677 de Abril 13 de 1987
4 81 81065 ARAUQUITA Decreto 1447 del 28 de Julio de 1971
5 81 81300 FORTUL Decreto 2926 de 1989
6 81 81736 SARAVENA Decreto Nal 204 de Feb 3 de 1976
MPIO_NAREA MPIO_NANO DPTO_CNMBR Shape_Leng Shape_Area COD_DEP DEPARTAMENTO
1 5787.9421 2017 ARAUCA 4.668016 0.47162612 81 ARAUCA
2 2281.4291 2017 ARAUCA 2.932376 0.18593602 81 ARAUCA
3 5212.6908 2017 ARAUCA 3.963937 0.42393331 81 ARAUCA
4 3046.8789 2017 ARAUCA 3.258765 0.24864660 81 ARAUCA
5 1158.6276 2017 ARAUCA 2.056433 0.09461063 81 ARAUCA
6 945.1354 2017 ARAUCA 1.294126 0.07721413 81 ARAUCA
COD_MUN MUNICIPIO GRUPO SUBGRUPO CULTIVO YEAR PERIODO
1 81001 ARAUCA TUBERCULOS Y PLATANOS PLATANO PLATANO 2018 2018
2 81591 PUERTO RONDON TUBERCULOS Y PLATANOS PLATANO PLATANO 2018 2018
3 81220 CRAVO NORTE TUBERCULOS Y PLATANOS PLATANO PLATANO 2018 2018
4 81065 ARAUQUITA TUBERCULOS Y PLATANOS PLATANO PLATANO 2018 2018
5 81300 FORTUL TUBERCULOS Y PLATANOS PLATANO PLATANO 2018 2018
6 81736 SARAVENA TUBERCULOS Y PLATANOS PLATANO PLATANO 2018 2018
Area_Siembra Area_Cosecha Produccion Rendimiento ESTADO CICLO
1 605 365 8019 22 FRUTO FRESCO PERMANENTE
2 451 236 3071 13 FRUTO FRESCO PERMANENTE
3 139 114 2052 18 FRUTO FRESCO PERMANENTE
4 6666 3646 72920 20 FRUTO FRESCO PERMANENTE
5 3527 2927 58540 20 FRUTO FRESCO PERMANENTE
6 4105 3805 83710 22 FRUTO FRESCO PERMANENTE
TEMP geometry
1 81001 POLYGON ((-70.68038 7.09393...
2 81591 POLYGON ((-70.87879 6.62133...
3 81220 POLYGON ((-70.40276 6.64639...
4 81065 POLYGON ((-71.58441 7.04298...
5 81300 POLYGON ((-71.54473 6.75924...
6 81736 POLYGON ((-71.76224 7.06602...
install.packages("lwgeom")
library(lwgeom)
Se re proyecta los municipios.
REP_PLATANO <- st_transform(PLATANO_MUNIC, crs = 3116)
Ahora se mapea. Se establecen las margenes,color de fondo,limites municipales,diseño y felcha indicativa del norte.
opar <- par(mar = c(0,0,1.2,0))
plot(st_geometry(REP_PLATANO), col = NA, border = "white", bg = "olivedrab2")
smoothLayer(
x = REP_PLATANO,
var = 'Produccion',
typefct = "exponential",
span = 25000,
beta = 2,
nclass = 10,
col = carto.pal(pal1 = 'orange.pal', n1 = 10),
border = "black",
lwd = 0.1,
mask = REP_PLATANO,
legend.values.rnd = -3,
legend.title.txt = "Produccion",
legend.pos = "topright",
add=TRUE
)
text(x = 650000, y = 1200000, cex = 0.6, adj = 0, font = 3, labels =
"Distance function:\n- type = exponential\n- beta = 2\n- span = 20 km")
layoutLayer(title = "DISTRIBUCION DE LA PRODUCCION DE PLATANO EN ARAUCA, 2018",
sources = "FUENTE: DANE and MADR, 2018",
author = "Diego Arturo Gonzalez Delgadillo",
frame = FALSE, north = FALSE, tabtitle = TRUE, theme = "grey.pal")
north(pos = "topleft")
Guardar Mapas
Se produse otro mapa de producción de platano en arauca en el año 2018. Esta vez se usaran sÃmbolos proporcionales y mapas de coropletas.El resultado se guardará como un archivo .png
png("C:/Users/Lina Maria Ayala.LinaMariaAyala/Documents/R/TRABAJOS GEOMATICA/ARAUCA/PLATANO_2018.png", width = 2048, height = 1526)
opar <- par(mar = c(0,0,5,5))
plot(st_geometry(REP_PLATANO), col="navajowhite", border="black",
bg = "white", lwd = 0.6)
propSymbolsChoroLayer(x = REP_PLATANO, var = "Produccion", var2 = "Rendimiento",
col = carto.pal(pal1 = "blue.pal", n1 = 3,
pal2 = "orange.pal", n2 = 3),
inches = 1.5, method = "q6",
border = "slateblue4", lwd = 1,
legend.title.cex = 2,5,
legend.values.cex = 2.1,
legend.var.pos = "topright",
legend.var2.pos = "left",
legend.var2.values.rnd = 2,
legend.var2.title.txt = "Rendimiento\n(in Ton/Ha)",
legend.var.title.txt = "PRODUCCION DE PLATANO EN 2018",
legend.var.style = "e")
labelLayer(
x = REP_PLATANO,
txt = "MPIO_CNMBR",
col= "black",
cex = 2.0,
font = 2,
halo = FALSE,
bg = "white",
r = 1.1,
overlap = FALSE,
show.lines = FALSE
)
layoutLayer(title="PRODUCCION Y RENDIMIENTO DE PLATANO EN ARAUCA, 2018",
author = "Diego Arturo Gonzalez Delgadillo",
sources = "FUENTE: MADR & DANE, 2018",
scale = 50, tabtitle = FALSE, frame = TRUE)
north(pos = "topleft")
title(main="PRODUCCION Y RENDIMIENTO DE PLATANO EN ARAUCA, 2018", cex.main=3,
sub= "FUENTE: MADR & DANE, 2018", cex.sub=3)
graticule = TRUE
par(opar)
dev.off()
library(ggplot2)
library(knitr)
include_graphics("C:/Users/Lina Maria Ayala.LinaMariaAyala/Documents/R/TRABAJOS GEOMATICA/ARAUCA/PLATANO_2018.png")
NA
Produccion de platano en Arauca, 2018
sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Colombia.1252 LC_CTYPE=Spanish_Colombia.1252
[3] LC_MONETARY=Spanish_Colombia.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Colombia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.28 lwgeom_0.2-3 SpatialPosition_2.0.1
[4] cartography_2.4.1 sf_0.9-0 rgeos_0.5-2
[7] readxl_1.3.1 forcats_0.5.0 stringr_1.4.0
[10] dplyr_0.8.5 purrr_0.3.3 readr_1.3.1
[13] tidyr_1.0.2 tibble_3.0.0 ggplot2_3.3.0
[16] tidyverse_1.3.0 raster_3.0-12 sp_1.4-1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4 lubridate_1.7.8 lattice_0.20-38 png_0.1-7
[5] class_7.3-15 digest_0.6.25 assertthat_0.2.1 R6_2.4.1
[9] cellranger_1.1.0 backports_1.1.5 reprex_0.3.0 evaluate_0.14
[13] e1071_1.7-3 httr_1.4.1 pillar_1.4.3 rlang_0.4.5
[17] rstudioapi_0.11 rmarkdown_2.1 rgdal_1.4-8 munsell_0.5.0
[21] broom_0.5.5 compiler_3.6.3 modelr_0.1.6 xfun_0.12
[25] base64enc_0.1-3 pkgconfig_2.0.3 htmltools_0.4.0 tidyselect_1.0.0
[29] codetools_0.2-16 fansi_0.4.1 crayon_1.3.4 dbplyr_1.4.2
[33] withr_2.1.2 grid_3.6.3 nlme_3.1-144 jsonlite_1.6.1
[37] gtable_0.3.0 lifecycle_0.2.0 DBI_1.1.0 magrittr_1.5
[41] units_0.6-6 scales_1.1.0 KernSmooth_2.23-16 cli_2.0.2
[45] stringi_1.4.6 fs_1.4.1 xml2_1.3.1 ellipsis_0.3.0
[49] generics_0.0.2 vctrs_0.2.4 tools_3.6.3 glue_1.3.2
[53] hms_0.5.3 yaml_2.2.1 slippymath_0.3.1 colorspace_1.4-1
[57] classInt_0.4-2 rvest_0.3.5 isoband_0.2.0 haven_2.2.0