This is an R Markdown Notebook. This is a infor for display thematic cartography a the Departament La Guajirain Colombia. It has been make, compiled and published in RPubs from RStudio.
Este cuaderno muestra información de algunos indices de la La Guajira Esta es una información para mostrar la cartografía temática en el Departamento de La Guajira en Colombia. Ha sido realizado, compilado y publicado en RPubs desde RStudio
Este cuaderno tiene como objetivo mostrar la elaboración de algunos mapas temáticos de La Guajira, aplicando los conocimientos aprendidos en la asignatura de Geomática Básica de la Universidad Nacional de Colombia en lenguaje R.
Según el IGAC, la cartografía temática es un conjunto de mapas elaborados que al incorporar la información objeto de estudio específico, representa las relaciones espaciales de una o varias variables geográficas, mediante la aplicación de técnicas visuales o semiología gráfica.
Estos mapas temáticos se elaboran a partir de la unión de bases de datos recopilados por entes gubernamentales con la cartográfica básica oficial, conformado por las capas temáticas y escala adecuada para el análisis de variables de estudio específico, todo esto mediante un programa especializado , para este caso R estudio.
Es de fácil visualización y entendimiento ya que se puede utilizar simbología en la cartografía temática, además se referencia variables de interés para los usuarios de la información geográfica, además sirve como un intercambio de esta información visual.
Son los que retrata los datos cuantitativos en diferentes colores sobre el mapa y puede mostrar la densidad, el porcentaje, el valor promedio o la cantidad de un evento dentro de un área geográfica. Los colores secuenciales representan valores de datos positivos o negativos crecientes o decrecientes. Normalmente, cada color también representa un rango de valores.
Se usan en otro tipo de mapa para representar datos asociados con ubicaciones, como ciudades. Los datos se muestran en estos mapas con símbolos de tamaño proporcional para mostrar las diferencias en las ocurrencias. Los círculos se usan con mayor frecuencia, pero los cuadrados y otras formas geométricas también son adecuados. La forma más común de cambiar el tamaño de estos símbolos es hacer que sus áreas sean proporcionales a los valores que se representarán mediante el software de mapeo o dibujo.
Este usa isolinas para representar valores continuos como los niveles de precipitación. Estos mapas también pueden mostrar valores tridimensionales, como la elevación, en mapas topográficos. En general, los datos para mapas isarítmicos se recopilan a través de puntos medibles (por ejemplo, estaciones meteorológicas) o se recopilan por área (por ejemplo, toneladas de Banano por hectárea por municipio). Los mapas isarítmicos también siguen la regla básica de que hay lados altos y bajos en relación con la isolina. Por ejemplo, en elevación, si la isolina es de 500 metros, entonces un lado debe ser más alto que 500 metros y un lado debe ser más bajo.
Se utiliza puntos para mostrar la presencia de un tema y mostrar un patrón espacial. Un punto puede representar una unidad o varias, dependiendo de lo que se esté representando.
Para este caso se utilizaran datos sobre Necesidades Básicas Insatisfechas (NBI) del Censo Nacional de Población y Vivienda 2018 que están disponibles en el Geoportal DANE.
Los mapas temáticos son útiles para transmitir información demográfica. Puede explorar varios mapas temáticos como los del DANE.
Anteriormente, se descargó el archivo NBI, en formato .xlsx, a mi computadora. Luego, utilicé Excel para eliminar datos de municipios no ubicados dentro del Departamento de Antioquia. También “limpié” los datos, es decir, eliminé varias filas con imágenes institucionales o sin información. Estas filas se ubicaron tanto al principio como al final del archivo original. Mantengo las columnas que se refieren a todo el municipio (es decir, eliminé las columnas correspondientes a “cabecera” y “zona rural”). Guarde los datos resultantes, correspondientes solo a municipios del departamento de La Guajira como NBI-La_Guajira.xlsx. Luego, cargué el archivo en el directorio “nbi” en la carpeta de mi proyecto en RStudio.
Se comienza limpiamdo la memoria
rm(list = ls())
Luego se instalan los diferentes paquetes necesarios para la elaboración de mapas temáticos como:
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)
Despues de instalar los paquetes necesarios se sigue con llamar las diferentes librerias a utilizar en la elaboración de mapas temáticos
library(tidyverse)
Registered S3 method overwritten by 'dplyr':
method from
print.rowwise_df
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
[37m-- [1mAttaching packages[22m --------------------------------------- tidyverse 1.3.0 --[39m
[37m[32mv[37m [34mggplot2[37m 3.3.0 [32mv[37m [34mpurrr [37m 0.3.3
[32mv[37m [34mtibble [37m 2.1.3 [32mv[37m [34mdplyr [37m 0.8.5
[32mv[37m [34mtidyr [37m 1.0.2 [32mv[37m [34mstringr[37m 1.4.0
[32mv[37m [34mreadr [37m 1.3.1 [32mv[37m [34mforcats[37m 0.5.0[39m
[37m-- [1mConflicts[22m ------------------------------------------ tidyverse_conflicts() --
[31mx[37m [34mdplyr[37m::[32mfilter()[37m masks [34mstats[37m::filter()
[31mx[37m [34mdplyr[37m::[32mlag()[37m masks [34mstats[37m::lag()[39m
library(readxl)
library(rgeos)
Loading required package: sp
rgeos version: 0.5-2, (SVN revision 621)
GEOS runtime version: 3.6.1-CAPI-1.10.1
Linking to sp version: 1.4-1
Polygon checking: TRUE
library(raster)
Attaching package: 㤼㸱raster㤼㸲
The following object is masked from 㤼㸱package:dplyr㤼㸲:
select
The following object is masked from 㤼㸱package:tidyr㤼㸲:
extract
library(ggplot2)
library(sf)
Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(fs)
library(cartography)
library(SpatialPosition)
nbi <- read_excel("C:/Users/familiar/Downloads/gb2/trabajos en R/informe 2/CNPV-2018-NBI-La_Guajira.xlsx")
nbi
nbi %>%
slice(which.max(NBI)) -> max_nbi
max_nbi
nbi %>%
slice(which.min(NBI)) -> min_nbi
min_nbi
nbi %>%
arrange(desc(NBI)) -> desc_nbi
desc_nbi
muni <- st_read("C:/Users/familiar/Downloads/gb2/La guajira/44_LA_GUAJIRA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp")
Reading layer `MGN_MPIO_POLITICO' from data source `C:\Users\familiar\Downloads\gb2\La guajira\44_LA_GUAJIRA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp' using driver `ESRI Shapefile'
Simple feature collection with 15 features and 9 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.66494 ymin: 10.39676 xmax: -71.11296 ymax: 12.45944
CRS: 4326
muni
Simple feature collection with 15 features and 9 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.66494 ymin: 10.39676 xmax: -71.11296 ymax: 12.45944
CRS: 4326
First 10 features:
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC MPIO_NAREA MPIO_NANO DPTO_CNMBR
1 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA
2 44 44098 DISTRACCIÓN Ordenanza 41 de Noviembre 30 de 1995 231.6880 2017 LA GUAJIRA
3 44 44110 EL MOLINO Ordenanza015 del 29 de Noviembre de 1989 242.1848 2017 LA GUAJIRA
4 44 44279 FONSECA 1954 473.7073 2017 LA GUAJIRA
5 44 44378 HATONUEVO Ordenanza 57 de Noviembre 9 de 1994 214.6399 2017 LA GUAJIRA
6 44 44420 LA JAGUA DEL PILAR Decreto presidencial 609 del 26 de Marzo de 1996 y ratificad 179.5909 2017 LA GUAJIRA
7 44 44855 URUMITA Ordenanza 36 de Diciembre 20 de 1983 246.2746 2017 LA GUAJIRA
8 44 44874 VILLANUEVA 1888 260.0959 2017 LA GUAJIRA
9 44 44001 RIOHACHA 1954 3088.7157 2017 LA GUAJIRA
10 44 44035 ALBANIA Ordenanza 001 del 27 de Marzo del 2000 546.0266 2017 LA GUAJIRA
Shape_Leng Shape_Area geometry
1 1.4953574 0.06621447 MULTIPOLYGON (((-72.59885 1...
2 0.9018563 0.01916877 MULTIPOLYGON (((-72.89246 1...
3 0.7100496 0.02000174 MULTIPOLYGON (((-72.96901 1...
4 1.3186028 0.03912942 MULTIPOLYGON (((-72.91056 1...
5 1.1453524 0.01775162 MULTIPOLYGON (((-72.6568 11...
6 0.9805011 0.01482556 MULTIPOLYGON (((-73.08581 1...
7 1.0506924 0.02033173 MULTIPOLYGON (((-73.00927 1...
8 0.8830655 0.02147866 MULTIPOLYGON (((-72.9918 10...
9 3.0307344 0.25561378 MULTIPOLYGON (((-72.89025 1...
10 1.4854163 0.04517060 MULTIPOLYGON (((-72.52248 1...
head(muni$MPIO_CNMBR)
[1] BARRANCAS DISTRACCIÓN EL MOLINO FONSECA HATONUEVO LA JAGUA DEL PILAR
15 Levels: ALBANIA BARRANCAS DIBULLA DISTRACCIÓN EL MOLINO FONSECA HATONUEVO LA JAGUA DEL PILAR MAICAO MANAURE ... VILLANUEVA
nbi_muni = left_join(muni, nbi, by=c("MPIO_CCDGO"= "CODIGO"))
Column `MPIO_CCDGO`/`CODIGO` joining factor and character vector, coercing into character vector
nbi_muni %>%
dplyr::select(Nom_Mun, MPIO_CCDGO, NBI) -> check_nbi_muni
head(check_nbi_muni)
Simple feature collection with 6 features and 3 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.18167 ymin: 10.39676 xmax: -72.48151 ymax: 11.16862
CRS: 4326
Nom_Mun MPIO_CCDGO NBI geometry
1 BARRANCAS 44078 39.89561 MULTIPOLYGON (((-72.59885 1...
2 DISTRACCIÓN 44098 24.93339 MULTIPOLYGON (((-72.89246 1...
3 EL MOLINO 44110 26.66954 MULTIPOLYGON (((-72.96901 1...
4 FONSECA 44279 19.30847 MULTIPOLYGON (((-72.91056 1...
5 HATONUEVO 44378 29.56089 MULTIPOLYGON (((-72.6568 11...
6 LA JAGUA DEL PILAR 44420 27.57453 MULTIPOLYGON (((-73.08581 1...
nbi_muni_new <- st_transform(nbi_muni, crs = 3116)
nbi_muni_new
Simple feature collection with 15 features and 20 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: 1045090 ymin: 1641659 xmax: 1322921 ymax: 1870870
CRS: EPSG:3116
First 10 features:
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC MPIO_NAREA MPIO_NANO DPTO_CNMBR
1 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA
2 44 44098 DISTRACCIÓN Ordenanza 41 de Noviembre 30 de 1995 231.6880 2017 LA GUAJIRA
3 44 44110 EL MOLINO Ordenanza015 del 29 de Noviembre de 1989 242.1848 2017 LA GUAJIRA
4 44 44279 FONSECA 1954 473.7073 2017 LA GUAJIRA
5 44 44378 HATONUEVO Ordenanza 57 de Noviembre 9 de 1994 214.6399 2017 LA GUAJIRA
6 44 44420 LA JAGUA DEL PILAR Decreto presidencial 609 del 26 de Marzo de 1996 y ratificad 179.5909 2017 LA GUAJIRA
7 44 44855 URUMITA Ordenanza 36 de Diciembre 20 de 1983 246.2746 2017 LA GUAJIRA
8 44 44874 VILLANUEVA 1888 260.0959 2017 LA GUAJIRA
9 44 44001 RIOHACHA 1954 3088.7157 2017 LA GUAJIRA
10 44 44035 ALBANIA Ordenanza 001 del 27 de Marzo del 2000 546.0266 2017 LA GUAJIRA
Shape_Leng Shape_Area Cod_Dep Nom_Dep Cod_Mun Nom_Mun NBI miseria Vivienda Servicios Hacinamiento Inasistencia
1 1.4953574 0.06621447 44 LA GUAJIRA 078 BARRANCAS 39.89561 18.113987 21.280695 18.092969 15.805514 2.290959
2 0.9018563 0.01916877 44 LA GUAJIRA 098 DISTRACCIÓN 24.93339 7.279759 7.975935 3.798883 12.230339 2.681564
3 0.7100496 0.02000174 44 LA GUAJIRA 110 EL MOLINO 26.66954 6.434008 10.957920 4.523912 9.277610 2.441476
4 1.3186028 0.03912942 44 LA GUAJIRA 279 FONSECA 19.30847 5.350540 8.389451 3.063398 6.819796 3.139310
5 1.1453524 0.01775162 44 LA GUAJIRA 378 HATONUEVO 29.56089 8.663422 10.757130 6.790403 11.639882 4.566546
6 0.9805011 0.01482556 44 LA GUAJIRA 420 LA JAGUA DEL PILAR 27.57453 7.723577 11.212737 8.604336 8.333333 1.016260
7 1.0506924 0.02033173 44 LA GUAJIRA 855 URUMITA 24.37420 6.851870 8.088741 5.634632 10.748994 3.072543
8 0.8830655 0.02147866 44 LA GUAJIRA 874 VILLANUEVA 18.03653 4.450052 8.928142 2.891933 6.092286 1.353841
9 3.0307344 0.25561378 44 LA GUAJIRA 001 RIOHACHA 36.01086 18.026919 18.435786 9.830346 20.018096 4.252672
10 1.4854163 0.04517060 44 LA GUAJIRA 035 ALBANIA 37.89462 19.122052 13.415009 7.158768 26.180966 3.176127
Economica geometry
1 7.590990 MULTIPOLYGON (((1161545 172...
2 7.185217 MULTIPOLYGON (((1129593 168...
3 6.994112 MULTIPOLYGON (((1121267 167...
4 4.662438 MULTIPOLYGON (((1127527 171...
5 6.399955 MULTIPOLYGON (((1155192 172...
6 7.859079 MULTIPOLYGON (((1108552 165...
7 5.281241 MULTIPOLYGON (((1116917 166...
8 4.273812 MULTIPOLYGON (((1118791 167...
9 10.302550 MULTIPOLYGON (((1129510 177...
10 14.521085 MULTIPOLYGON (((1169727 175...
summary(nbi_muni_new)
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC MPIO_NAREA
44:15 Length:15 ALBANIA :1 1954 :4 Min. : 179.6
Class :character BARRANCAS :1 1888 :1 1st Qu.: 244.2
Mode :character DIBULLA :1 1935 :1 Median : 546.0
DISTRACCIÓN:1 1956 :1 Mean :1374.8
EL MOLINO :1 Decreto presidencial 609 del 26 de Marzo de 1996 y ratificad:1 3rd Qu.:1684.8
FONSECA :1 Ordenanza 001 del 27 de Marzo del 2000 :1 Max. :7886.1
(Other) :9 (Other) :6
MPIO_NANO DPTO_CNMBR Shape_Leng Shape_Area Cod_Dep Nom_Dep Cod_Mun
Min. :2017 LA GUAJIRA:15 Min. :0.710 Min. :0.01483 Length:15 Length:15 Length:15
1st Qu.:2017 1st Qu.:1.016 1st Qu.:0.02017 Class :character Class :character Class :character
Median :2017 Median :1.485 Median :0.04517 Mode :character Mode :character Mode :character
Mean :2017 Mean :1.897 Mean :0.11381
3rd Qu.:2017 3rd Qu.:2.288 3rd Qu.:0.13948
Max. :2017 Max. :6.113 Max. :0.65355
Nom_Mun NBI miseria Vivienda Servicios Hacinamiento Inasistencia Economica
Length:15 Min. :18.04 Min. : 4.450 Min. : 5.462 Min. : 2.892 Min. : 6.092 Min. : 1.016 Min. : 4.274
Class :character 1st Qu.:24.65 1st Qu.: 7.066 1st Qu.: 8.659 1st Qu.: 5.079 1st Qu.:10.013 1st Qu.: 2.562 1st Qu.: 6.684
Mode :character Median :29.56 Median : 8.663 Median :11.213 Median : 7.542 Median :13.666 Median : 3.139 Median : 7.591
Mean :39.45 Mean :19.248 Mean :18.712 Mean :11.393 Mean :21.831 Mean : 4.883 Mean :12.477
3rd Qu.:47.62 3rd Qu.:25.062 3rd Qu.:19.858 3rd Qu.:14.797 3rd Qu.:29.114 3rd Qu.: 5.093 3rd Qu.:14.431
Max. :88.26 Max. :60.349 Max. :63.123 Max. :35.656 Max. :59.941 Max. :16.346 Max. :36.913
geometry
MULTIPOLYGON :15
epsg:3116 : 0
+proj=tmer...: 0
se utilizan las diferentes librerias de los paquetes de cartografía para que R pueda trabajar y elaborar los diferentes mapas tematicos
#instalar paquete ("RColorBrewer")
library(RColorBrewer)
library(leaflet)
para este clase de mapas se utilizan simbolos que nos permiten visualizar con facilidad los datos de los diferentes municipios en La Guajira
# download osm tiles
mun.osm <- getTiles(
x = nbi_muni_new,
type = "OpenStreetMap",
zoom = 8,
cachedir = TRUE,
crop = FALSE
)
ning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Infning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Infning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Inf
# set margins
opar <- par(mar = c(0,0,1.2,0))
# plot osm tiles
tilesLayer(x = mun.osm)
# plot municipalities (only borders are plotted)
plot(st_geometry(nbi_muni_new), col = NA, border = "grey", add=TRUE)
# plot NBI
propSymbolsLayer(
x = nbi_muni_new,
var = "NBI",
inches = 0.25,
col = "brown4",
legend.pos = "topright",
legend.title.txt = "Total NBI"
)
# layout
layoutLayer(title=" -NBI- Distribución datos de NBI en La Guajira",
author = "Eduardo Lezama M.",
sources = "Fuente: DANE, 2018",
frame = TRUE, north = FALSE, tabtitle = TRUE)
# north arrow
north(pos = "topleft")
Es un tipo de mapa temático en el que las áreas se sombrean de distintos colores, frecuentemente de la misma gama cromática, que representan distintos valores de una variable estadística característica de la región geográfica de La Guajira, como puede ser la densidad de población o para este caso la distribución del NBI
# set margins
opar <- par(mar = c(0,0,1.2,0))
# set figure background color
par(bg="grey90")
# plot municipalities (only the backgroung color is plotted)
plot(st_geometry(nbi_muni_new), col = NA, border = NA, bg = "#aadaff")
# plot NBI
choroLayer(
x = nbi_muni_new,
var = "NBI",
method = "geom",
nclass=5,
col = carto.pal(pal1 = "sand.pal", n1 = 5),
border = "white",
lwd = 0.15,
legend.pos = "topright",
legend.title.txt = "NBI",
add = TRUE
)
# layout
layoutLayer(title=" Otra forma de ver La Distribición NBI en La Guajira",
author = "Eduardo Lezama M.",
sources = "Fuente: DANE, 2018",
frame = TRUE, north = TRUE, tabtitle = TRUE, col="black")
# north arrow
north(pos = "topleft")
La función propSymbolsTypoLayer () crea un mapa de símbolos que son proporcionales a los valores de una primera variable y coloreados para reflejar las modalidades de una segunda variable cualitativa. Se utiliza una combinación de argumentos propSymbolsLayer () y typoLayer ().
Primero, necesitamos crear una variable cualitativa. Usemos la función mutate para esta tarea.
nbi_munic_2 <- dplyr::mutate(nbi_muni_new, poverty = ifelse(miseria > 20, "Extreme",
ifelse(Hacinamiento > 10, "High", "Intermediate")))
###
#
head(nbi_munic_2)
Simple feature collection with 6 features and 21 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: 1098079 ymin: 1641659 xmax: 1174408 ymax: 1727256
CRS: EPSG:3116
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC MPIO_NAREA MPIO_NANO DPTO_CNMBR
1 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA
2 44 44098 DISTRACCIÓN Ordenanza 41 de Noviembre 30 de 1995 231.6880 2017 LA GUAJIRA
3 44 44110 EL MOLINO Ordenanza015 del 29 de Noviembre de 1989 242.1848 2017 LA GUAJIRA
4 44 44279 FONSECA 1954 473.7073 2017 LA GUAJIRA
5 44 44378 HATONUEVO Ordenanza 57 de Noviembre 9 de 1994 214.6399 2017 LA GUAJIRA
6 44 44420 LA JAGUA DEL PILAR Decreto presidencial 609 del 26 de Marzo de 1996 y ratificad 179.5909 2017 LA GUAJIRA
Shape_Leng Shape_Area Cod_Dep Nom_Dep Cod_Mun Nom_Mun NBI miseria Vivienda Servicios Hacinamiento Inasistencia
1 1.4953574 0.06621447 44 LA GUAJIRA 078 BARRANCAS 39.89561 18.113987 21.280695 18.092969 15.805514 2.290959
2 0.9018563 0.01916877 44 LA GUAJIRA 098 DISTRACCIÓN 24.93339 7.279759 7.975935 3.798883 12.230339 2.681564
3 0.7100496 0.02000174 44 LA GUAJIRA 110 EL MOLINO 26.66954 6.434008 10.957920 4.523912 9.277610 2.441476
4 1.3186028 0.03912942 44 LA GUAJIRA 279 FONSECA 19.30847 5.350540 8.389451 3.063398 6.819796 3.139310
5 1.1453524 0.01775162 44 LA GUAJIRA 378 HATONUEVO 29.56089 8.663422 10.757130 6.790403 11.639882 4.566546
6 0.9805011 0.01482556 44 LA GUAJIRA 420 LA JAGUA DEL PILAR 27.57453 7.723577 11.212737 8.604336 8.333333 1.016260
Economica geometry poverty
1 7.590990 MULTIPOLYGON (((1161545 172... High
2 7.185217 MULTIPOLYGON (((1129593 168... High
3 6.994112 MULTIPOLYGON (((1121267 167... Intermediate
4 4.662438 MULTIPOLYGON (((1127527 171... Intermediate
5 6.399955 MULTIPOLYGON (((1155192 172... High
6 7.859079 MULTIPOLYGON (((1108552 165... Intermediate
library(sf)
library(cartography)
# set margins
opar <- par(mar = c(0,0,1.2,0))
# Plot the municipalities
plot(st_geometry(nbi_munic_2), col="#f2efe9", border="#b38e43", bg = "#aad3df",
lwd = 0.5)
# Plot symbols with choropleth coloration
propSymbolsTypoLayer(
x = nbi_munic_2,
var = "NBI",
inches = 0.3,
symbols = "square",
border = "white",
lwd = .5,
legend.var.pos = c(1250000, 1658000),
legend.var.title.txt = "NBI",
var2 = "poverty",
legend.var2.values.order = c("Extreme", "High",
"Intermediate"),
col = carto.pal(pal1 = "multi.pal", n1 = 3),
legend.var2.pos = c(1180000,1640000),
legend.var2.title.txt = "Nivel de pobresa"
)
# layout
layoutLayer(title=" Distribución NBI en La Guajira",
author = "Eduardo Lezama M.",
sources = "Fuente: DANE, 2018",
scale = 1, tabtitle = TRUE, frame = TRUE)
# north arrow
north(pos = "topleft")
se combinan funciones como choroLayer y labelLayer
library(sf)
library(cartography)
# set margins
opar <- par(mar = c(0,0,1.2,0))
# set figure background color
par(bg="grey25")
# plot municipalities
plot(st_geometry(nbi_munic_2), col = "#e4e9de", border = "darkseagreen4",
bg = "grey75", lwd = 0.5)
# plot NBI
choroLayer(
x = nbi_muni_new,
var = "NBI",
method = "geom",
nclass=5,
col = carto.pal(pal1 = "sand.pal", n1 = 5),
border = "white",
lwd = 0.5,
legend.pos = "topright",
legend.title.txt = "NBI",
add = TRUE
)
# plot labels
labelLayer(
x = nbi_munic_2,
txt = "Nom_Mun",
col= "white",
cex = 0.4,
font = 8,
halo = TRUE,
bg = "grey25",
r = 0.1,
overlap = FALSE,
show.lines = FALSE
)
# map layout
layoutLayer(
title = "Municipios de La Guajira",
sources = "Fuente: DANE, 2018",
author = "Eduardo Lezama M.",
frame = TRUE,
north = TRUE,
tabtitle = TRUE,
theme = "taupe.pal"
)
Son en sí isolíneas que se representan en un mapa , es decir lineas, rectas o curvas, que describen la intersección de una superficie real o hipotética con uno o más planos horizontales. La configuración de estas curvas permite a los lectores del mapa inferir el gradiente relativo de la variable o parámetro y estimar un valor en un lugar determinado.
crops2018 <- read_excel("C:/Users/familiar/Downloads/gb2/La guajira/Eva_Agro_Muni_LaGuajira_EVA.xlsx")
head(crops2018)
crops2018 %>%
filter(CULTIVO == "CAFE") -> cafe2018
#Create a new attribute which matches municipalities codes:
cafe2018$TEMP <- as.character(cafe2018$C0D_MUN)
cafe2018$MPIO_CCDGO <- as.factor(paste( cafe2018$TEMP, sep=""))
#Now, make the join:
cafe_munic = left_join(muni, cafe2018, by="MPIO_CCDGO")
Column `MPIO_CCDGO` joining factors with different levels, coercing to character vector
## Warning: Column `MPIO_CCDGO` joining factors with different levels, coercing to
## character vector
#Check the output:
head(cafe_munic)
Simple feature collection with 6 features and 27 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -72.91242 ymin: 10.81934 xmax: -72.48151 ymax: 11.13662
CRS: 4326
DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR MPIO_CRSLC MPIO_NAREA MPIO_NANO DPTO_CNMBR Shape_Leng Shape_Area COD_DEP_ DEPARTAMENTO C0D_MUN MUNICIPIO
1 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA 1.495357 0.06621447 44 LA GUAJIRA 44078 BARRANCAS
2 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA 1.495357 0.06621447 44 LA GUAJIRA 44078 BARRANCAS
3 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA 1.495357 0.06621447 44 LA GUAJIRA 44078 BARRANCAS
4 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA 1.495357 0.06621447 44 LA GUAJIRA 44078 BARRANCAS
5 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA 1.495357 0.06621447 44 LA GUAJIRA 44078 BARRANCAS
6 44 44078 BARRANCAS 1935 800.9418 2017 LA GUAJIRA 1.495357 0.06621447 44 LA GUAJIRA 44078 BARRANCAS
GRUPO_DE_CULTIVO SUBGRUPO_DE_CULTIVO CULTIVO DESAGREGACION REGIONAL_Y/O_SISTEMA PRODUCTIVO AÑO PERIODO A\u0081rea_Sembrada_ha
1 OTROS PERMANENTES CAFE CAFE CAFE 2007 2007 719
2 OTROS PERMANENTES CAFE CAFE CAFE 2008 2008 763
3 OTROS PERMANENTES CAFE CAFE CAFE 2009 2009 692
4 OTROS PERMANENTES CAFE CAFE CAFE 2010 2010 660
5 OTROS PERMANENTES CAFE CAFE CAFE 2011 2011 744
6 OTROS PERMANENTES CAFE CAFE CAFE 2012 2012 744
A\u0081rea_Cosechada_ha Produccion_ton Rendimiento_t/ha ESTADO_FISICO_PRODUCCION NOMBRE_CIENTIFICO CICLO_DE_CULTIVO TEMP
1 702 421 1 CAFE VERDE EQUIVALENTE COFFEA ARABICA PERMANENTE 44078
2 719 431 1 CAFE VERDE EQUIVALENTE COFFEA ARABICA PERMANENTE 44078
3 567 340 1 CAFE VERDE EQUIVALENTE COFFEA ARABICA PERMANENTE 44078
4 430 258 1 CAFE VERDE EQUIVALENTE COFFEA ARABICA PERMANENTE 44078
5 430 215 1 CAFE VERDE EQUIVALENTE COFFEA ARABICA PERMANENTE 44078
6 638 351 1 CAFE VERDE EQUIVALENTE COFFEA ARABICA PERMANENTE 44078
geometry
1 MULTIPOLYGON (((-72.59885 1...
2 MULTIPOLYGON (((-72.59885 1...
3 MULTIPOLYGON (((-72.59885 1...
4 MULTIPOLYGON (((-72.59885 1...
5 MULTIPOLYGON (((-72.59885 1...
6 MULTIPOLYGON (((-72.59885 1...
rep_cafe <- st_transform(cafe_munic, crs = 3116)
# set margins
opar <- par(mar = c(0,0,1.2,0))
# plot municipalities (only the backgroung color is plotted)
plot(st_geometry(rep_cafe), col = NA, border = "black", bg = "grey75")
library(sf)
# plot isopleth map
smoothLayer(
x = rep_cafe,
var = 'Produccion_ton',
typefct = "exponential",
span = 50,
beta = 2,
nclass = 10,
col = carto.pal(pal1 = 'green.pal', n1 = 10),
border = "grey",
lwd = 0.1,
mask = rep_cafe,
legend.values.rnd = -3,
legend.title.txt = "Production",
legend.pos = "topright",
add=TRUE
)
Error in polypath(p_bind(x[[i]]), border = border[i], lty = lty[i], lwd = lwd[i], :
plot.new has not been called yet
Un codigo para poder guardar los maps elaborados en R
### open the plot
png("C:/Users/familiar/Downloads/gb2/trabajos en R/LA Guajira/Cafe_2018.png", width = 2048, height = 1526)
# set margins
opar <- par(mar = c(0,0,5,5))
# Plot the municipalities
plot(st_geometry(rep_cafe), col="darkseagreen3", border="darkseagreen4",
bg = "white", lwd = 0.6)
# Plot symbols with choropleth coloration
propSymbolsChoroLayer(x = rep_cafe, var = "Produccion_ton", var2 = "Rendimiento_t/ha",
col = carto.pal(pal1 = "green.pal", n1 = 3,
pal2 = "red.pal", n2 = 3),
inches = 0.8, method = "q6",
border = "grey50", lwd = 1,
legend.title.cex = 1.5,
legend.values.cex = 1.0,
legend.var.pos = "right",
legend.var2.pos = "left",
legend.var2.values.rnd = 2,
legend.var2.title.txt = "Rendimiento/n(in Ton/Ha)",
legend.var.title.txt = "Producción Cafe 2018",
legend.var.style = "e")
Error in findInterval(var, distr, all.inside = TRUE) :
'vec' must be sorted non-decreasingly and not contain NAs
sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Latin America.1252 LC_CTYPE=Spanish_Latin America.1252 LC_MONETARY=Spanish_Latin America.1252
[4] LC_NUMERIC=C LC_TIME=Spanish_Latin America.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] leaflet_2.0.3 RColorBrewer_1.1-2 SpatialPosition_2.0.1 cartography_2.4.1 fs_1.4.1 sf_0.9-2
[7] raster_3.0-12 rgeos_0.5-2 sp_1.4-1 readxl_1.3.1 forcats_0.5.0 stringr_1.4.0
[13] dplyr_0.8.5 purrr_0.3.3 readr_1.3.1 tidyr_1.0.2 tibble_2.1.3 ggplot2_3.3.0
[19] tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4 lubridate_1.7.8 lattice_0.20-40 png_0.1-7 class_7.3-15 assertthat_0.2.1 digest_0.6.25
[8] R6_2.4.1 cellranger_1.1.0 backports_1.1.5 reprex_0.3.0 e1071_1.7-3 httr_1.4.1 pillar_1.4.3
[15] rlang_0.4.5 curl_4.3 rstudioapi_0.11 rgdal_1.4-8 htmlwidgets_1.5.1 munsell_0.5.0 broom_0.5.5
[22] compiler_3.6.3 modelr_0.1.6 xfun_0.12 pkgconfig_2.0.3 htmltools_0.4.0 tidyselect_1.0.0 codetools_0.2-16
[29] fansi_0.4.1 crayon_1.3.4 dbplyr_1.4.2 withr_2.1.2 grid_3.6.3 lwgeom_0.2-3 nlme_3.1-145
[36] jsonlite_1.6.1 gtable_0.3.0 lifecycle_0.2.0 DBI_1.1.0 magrittr_1.5 units_0.6-6 scales_1.1.0
[43] KernSmooth_2.23-16 cli_2.0.2 stringi_1.4.6 xml2_1.3.1 generics_0.0.2 vctrs_0.2.4 tools_3.6.3
[50] glue_1.3.2 hms_0.5.3 crosstalk_1.1.0.1 slippymath_0.3.1 colorspace_1.4-1 classInt_0.4-2 rvest_0.3.5
[57] isoband_0.2.0 knitr_1.28 haven_2.2.0
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.