Mediante este cuaderno R Markdown Notebook. Usaremos algunas librerias como \(dpylr\) que nos proporciona “gramatica” para la manipulacion y operaciones de data frames. mas info), \(sf\) soporte para funciones simples mas info y \(leaflet\) (la cual nos permite la creacion de mapas web. mas info) entre otras.
Los datos que usamos en este informe fueron descargados del Geoportal DANE en el cual encontramos los datos de las Necesidades Basicas Insatisfechas (NBI) que usamos para desarrollar este informe.
Usamos la funcion \(rm\) la cual nos permite remover los objetos del entorno de trabajo, limiando asi la memoria con lo cual tendremos un mejor desempeño en nuestro entorno de trabajo:
rm(list = ls())
Ahora instalaremos las librerias que nescesitamos. Usanodo el siguiente comando se instalan los paquetes solo si no se han instalado previamente:
list.of.packages <- c("tidyverse", "rgeos", "sf", "raster", "cartography", "SpatialPosition", "rgdal")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
Cargamos las librerias usando la funcion \(library\):
library(tidyverse)
## -- Attaching packages ------------------------------------------------ tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.3 v dplyr 1.0.2
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts --------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sp)
library(readxl)
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-2
## 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(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(cartography)
library(SpatialPosition)
library(rgdal)
## rgdal: version: 1.5-17, (SVN revision 1070)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
## Path to GDAL shared files: C:/Users/JUANPABLO/Documents/R/win-library/4.0/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
## Path to PROJ shared files: C:/Users/JUANPABLO/Documents/R/win-library/4.0/rgdal/proj
## Linking to sp version:1.4-4
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
Usamos la funcion \(read_excel\) la cual nos permite leer archivos Excel, para leer el archivo NBI_Valle_del_Cauca.xlsx previamente descargado de la pagina oficial sobre datos de Necesidades Basicas Insatisfechas (NBI), y guardamos los datos del archivo en un data.frame que llamaremos nbi:
nbi <- read_excel("C:/Users/JUANPABLO/Documents/R/GB/Datos/NBI_Valle_del_Cauca.xlsx")
Observamos los primeros atributos del \(data.frame\) nbi usando la funcion \(head\). aqui obtenemos los datos que que hacen referencia a los valores de Necesidades Basicas Insatisfechas (NBI) clasficicadas para cada municipio del departamento de Valle del Cauca:
head(nbi)
Debido a que la columna CODIGO es una variable de tipo double, nescesitamos convertirla a tipo character para lo cual usamos la funcion \(as.character\) y observamos de nuevo los primeros atributos del \(data.frame\) nbi:
nbi$CODIGO <- as.character(nbi$CODIGO)
head(nbi)
Usamos la funcion \(slice\) para clasificar el municipio con mayor porcentaje de NBI, guardamos los datos en un obtejo de tipo \(data.frame\) que llamamos max_nbi:
max_nbi <- nbi %>%
slice(which.max(NBI))
max_nbi
Del proceso anterior obtuvimos que el mayor porcentaje de NBI se registro en la Ciudad de BUENAVENTURA:
Busquemos cual es el municipio con el porcentaje mas bajo de NBI: Repetimos el proceso anterior, esta vez para identificar cual es el Municipio con menor porcentaje de NBI, guardamos los datos en un objeto de tipo \(data.frame\) que llamamos min_nbi:
min_nbi <- nbi %>%
slice(which.min(NBI))
min_nbi
De acuerdo a la clasificacion anterior obtuvimos que el menor porcentaje de NBI se registro en el municipio de GUADALAJARA DE BUGA.
Clasifiquemos los municipios por NBI en orden descendente: Usamos la funcion \(arrange\) para clasificar los municipios en orden descendente de acuerdo al porcentaje de NBI, almacenamos los nuevos datos en un objeto de tipo \(data.frame\), que llamamos desc_nbi:
desc_nbi <- nbi %>%
arrange(desc(NBI))
desc_nbi
Leemos los datos del \(Marco\) \(Geoestadistico\) \(Departamental\) descargado de DANE Geoportal, usando la libreria \(sf\) y los almacenamos en un nuevo data.frame que llamaremos Vall_munic:
vall_munic <- st_read("C:/Users/JUANPABLO/Documents/R/GB/Datos/MGN2017_76_VALLE_DEL_CAUCA/76_VALLE_DEL_CAUCA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp")
## Reading layer `MGN_MPIO_POLITICO' from data source `C:\Users\JUANPABLO\Documents\R\GB\Datos\MGN2017_76_VALLE_DEL_CAUCA\76_VALLE_DEL_CAUCA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp' using driver `ESRI Shapefile'
## Simple feature collection with 42 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -77.54977 ymin: 3.091239 xmax: -75.70724 ymax: 5.047394
## geographic CRS: WGS 84
Observamos los primeros Municipios usando la funcion \(head\), e indicando que queremos leer el \(data.frame\) vall_munic y usamos el signo $ para indicar que solo queremos ver los datos de la columna MPIO_CCDGO, la cual contiene los nombres municipales del valle del cauca:
head(vall_munic$MPIO_CNMBR)
## [1] "CALI" "ANDALUCÍA" "ANSERMANUEVO" "ARGELIA" "BUGA"
## [6] "BUGALAGRANDE"
Usamos \(left\)_\(join\) para unir los municipios y los datos de NBI en un \(data.frame\) que llamamos nbi_munic.
nbi_munic = left_join(vall_munic, nbi, by=c("MPIO_CCDGO"="CODIGO"))
Usamos la libreria \(dplyr\) que nos permite filtrar los datos de nbi_munic, almanecamos los datos en Check_nbi_munic:
check_nbi_munic <- nbi_munic %>%
dplyr::select(MUNICIPIO, MPIO_CCDGO, NBI)
head(check_nbi_munic)
COnvertimos el Sistema de Coordanadas de Referencia al sistema de referencia EPSG 3116 usando para la zona de Bogota-Colombia:
nbi_munic_new <- st_transform(nbi_munic, crs = 3116)
Para esta representacion usaremos los datos del \(data.frame\) nbi que cargamos y filtramos anteriormente.
Descargamos los mapas nescesarios de OpenStreetMap.
mun.osm <- getTiles(
x = nbi_munic_new,
type = "OpenStreetMap",
zoom = 8,
cachedir = TRUE,
crop = FALSE)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
Usando la funcion ChoroLayer Ploteamos un mapa tematico sobre el nbi municipal en el departamendo del Valle del Cauca que nos permite visualizar y comprender mejor los datos estadisticos.
opar <- par(mar = c(0,0,1.2,0))
tilesLayer(x = mun.osm)
plot(st_geometry(nbi_munic_new), col = NA, border= NA, add=TRUE)
choroLayer(
x=nbi_munic_new,
var = "NBI",
method = "geom",
nclass = 5,
col = carto.pal(pal1 = "blue.pal", n1 = 5),
border = "black",
lwd = 0.5,
legend.pos = NA,
legend.title.txt = "NBI",
add = TRUE
)
propSymbolsLayer(
x=nbi_munic_new,
var="NBI",
inches=0.13,
col="green",
legend.pos = "topright",
legend.title.txt = "Porcentaje de NBI"
)
labelLayer(
x = nbi_munic_new,
txt = "MUNICIPIO",
col= "white",
cex = 0.4,
font = 4,
halo = TRUE,
bg = "black",
r = 0.1,
overlap = FALSE,
show.lines = FALSE
)
layoutLayer(title="Distribucion de NBI en Valle del Cauca",
sources="Sources:DANE, 2018\n© OpenStreetMap",
author = "Juan Cañon",
frame = TRUE, north=FALSE, tabtitle = TRUE, theme="blue.pal")
north(pos = "topleft")
usando el siguiente mapa tematico, visualizaremos el porcentaje correspondiente a los servicios para cada municipio en el departamento del Valle del Cauca.
usando el siguiente codigo descargamos un mapa en este caso de OpenStreetMap
mun.NatGeo <- getTiles(
x = nbi_munic_new,
type = "OpenStreetMap",
zoom = 8,
cachedir = TRUE,
crop = FALSE)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
Ploteamos el mapa con la informacion de nuestro ineteres para una mejor comprension de los datos.
opar <- par(mar=c(0,0,1.2,0))
tilesLayer(x = mun.NatGeo)
plot(st_geometry(nbi_munic_new), col = NA, border = "grey", add=TRUE)
choroLayer(
x=nbi_munic_new,
var = "SERVICIOS",
method = "geom",
nclass = 5,
col = carto.pal(pal1 = "orange.pal", n1 = 5),
border = "white",
lwd = 0.5,
legend.pos = c(530000, 1000000),
legend.title.txt = "Servicios",
add = TRUE
)
labelLayer(
x = nbi_munic_new,
txt = "MUNICIPIO",
col= "yellow",
cex = 0.4,
font = 4,
halo = TRUE,
bg = "grey25",
r = 0.1,
overlap = FALSE,
show.lines = FALSE
)
layoutLayer(title = "NBI Distribution in Valle del Cauca",
sources = "Source:DANE, 2018",
author = "Juan Cañon",
frame=TRUE, north =TRUE, tabtitle = TRUE, theme="turquoise.pal")
north(pos = "topleft")
par(opar)
En el siguiente mapa tematico representamos dos variables de nuestro interes como son Pobreza y Hacinamiento.
usando la libreria \(dplyr\) establecemos los valores correspondientes a los porcentajes de cada variable.
nbi_munic_2 <- dplyr::mutate(nbi_munic_new, poverty=ifelse(MISERIA > 5, "Extreme",
ifelse(HACINAMIENTO > 3, "High", "Intermediate")))
Usando el siguiente codigo descargamos un proveedor para el mapa de fondo, en este caso Esri.
mun.WoIm <- getTiles(
x = nbi_munic_new,
type = "Esri",
zoom = 8,
cachedir = TRUE,
crop = FALSE)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
Ploteamos el Mapa de las dos variables mencionadas anteriormente.
library(sf)
library(cartography)
library(RColorBrewer)
opar <- par(mar = c(0,0,1.2,0))
tilesLayer(x = mun.WoIm)
# Plot the municipalities
plot(st_geometry(nbi_munic_2), col= 1:9, border="black", bg = NA,
lwd = 0.5, add=TRUE)
propSymbolsTypoLayer(
x = nbi_munic_2,
var = "HACINAMIENTO",
inches = 0.3,
symbols = "square",
border = "white",
lwd = .5,
legend.var.pos = c(530000, 1050000),
legend.var.title.txt = "Hacinamiento",
var2 = "poverty",
legend.var2.values.order = c("Extreme", "High",
"Intermediate"),
col = carto.pal(pal1 = "multi.pal", n1 = 3),
legend.var2.pos = c(530000, 850000),
legend.var2.title.txt = "Pobreza"
)
labelLayer(
x = nbi_munic_new,
txt = "MUNICIPIO",
col= "green",
cex = 0.4,
font = 4,
halo = TRUE,
bg = "grey25",
r = 0.1,
overlap = FALSE,
show.lines = FALSE
)
layoutLayer(title="Pobreza y Hacinamiento en Valle",
author = "Juan Pablo cañon",
sources = "Source: DANE, 2018",
scale = 1, tabtitle = TRUE, frame = TRUE, theme="orange.pal")
north(pos = "topleft")
usando el siguiente mapa tematico visualizamos los datos sobre el porcenteaje economico para cada municipio del departamendo del Valle del Cauca.
Descargamo el mapa base, en este caso el proveedor en es Esri.DeLorme.
mun.DeLor <- getTiles(
x = nbi_munic_new,
type = "Esri.DeLorme",
zoom = 8,
cachedir = TRUE,
crop = FALSE)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
Ploteamos el mapa economico usando cloropletas asi:
library(sf)
library(cartography)
tilesLayer(x = mun.DeLor)
plot(st_geometry(nbi_munic_2), col= 1:9, border="blue", bg = NA,
lwd = 0.5, add=TRUE)
choroLayer(
x=nbi_munic_new,
var="NBI",
method="geom",
nclass=5,
col= carto.pal(pal1 = "orange.pal", n1 = 5),
border= "white",
lwd= 0.5,
legend.pos= c(530000, 1000000),
legend.title.txt= "Economia",
add= TRUE
)
labelLayer(
x= nbi_munic_2,
txt = "MUNICIPIO",
col= "white",
cex= 0.4,
font = 4,
halo = TRUE,
bg = "grey25",
r = 0.1,
overlap = FALSE,
show.lines = FALSE
)
layoutLayer(
title = "Economia Municipal Valle del Cauca",
sources = "source: DANE, 2018",
author = "Juan Pablo Cañon Sosa",
frame = TRUE,
north = TRUE,
tabtitle = TRUE,
theme = "taupe.pal"
)
Del mapa podemos observar algunos de los municipios con la mejor economia, como son :(Buenaventura, Bolivar, Trujillo) entre otros.
Para visualizar los datos de produccion de este Cultivo en el año 2018 primero leemos el documento tipo Excel sobre el cual trabajaremos.
crops2018 <- read_excel("C:/Users/JUANPABLO/Documents/R/GB/Datos/EVA_Valle_del_Cauca_2018.xlsx")
Observamos los datos de documento con los datos que cargamos anteriormente.
head(crops2018)
Filtramos los datos ubicando el Cultivo de nuestro interes.
caña_azucar <- crops2018%>%
filter(CULTIVO == "CAÑA AZUCARERA")
Creamos una nueva columna para guardar los datos de COD_MUN esta vez como objetos de tipo character:
caña_azucar$TEMP <- as.character(caña_azucar$COD_MUN)
Creamo suna nueva columna para guardar los datos anteriores, pero convirtiendolos en datos tipo factor:
caña_azucar$MPIO_CCDGO <- as.factor(paste(caña_azucar$TEMP, sep=""))
Usando la funcion \(left.join\) unimos los datos de nuestro interes.
caña_azucar_munic = left_join(vall_munic, caña_azucar, by="MPIO_CCDGO")
visualizamos el resultado de la union de datos anterior.
head(caña_azucar_munic)
asignamos un sistema de coordanadas a los datos, en este caso usamos el CRS:3116 el cual hace referencia a la zona de la capital Bogota.
rep_caña_azucar <- st_transform(caña_azucar_munic, crs= 3116)
Ploteamos el mapa tematico de Isolineas usando la Variable de Produccion en el año 2018.
# set margins
tilesLayer(x = mun.DeLor)
# Plot the municipalities
plot(st_geometry(nbi_munic_2), col= 1:9, border="blue", bg = NA,
lwd = 0.5, add=TRUE)
smoothLayer(
x = rep_caña_azucar,
var = 'Produccion',
typefct = "exponential",
span = 25000,
beta = 2,
nclass = 10,
col = carto.pal(pal1 = 'turquoise.pal', n1 = 10),
border = "black",
lwd = 0.1,
mask = rep_caña_azucar,
legend.values.rnd = -3,
legend.title.txt = "Production",
legend.pos = "topright",
add=TRUE
)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
## Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded datum Marco Geocentrico Nacional de Referencia in CRS
## definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
## Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded datum Marco Geocentrico Nacional de Referencia in CRS
## definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum Unknown based on GRS80 ellipsoid in CRS definition
## Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded datum Marco Geocentrico Nacional de Referencia in CRS
## definition
# annotation on the map
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")
# layout
layoutLayer(title = "Coffee Production Distribution in Antioquia",
sources = "Sources: DANE and MADR, 2018",
author = "Ivan Lizarazo",
frame = FALSE, north = FALSE, tabtitle = TRUE, theme = "harmo.pal")
# north arrow
north(pos = "topleft")
Del mapa anterior observamos una mayor concentracion de la produccion en la zona Nororiental del departamento.
#
par(opar)
Filtramos los datos ubicando el Cultivo de nuestro interes.
caña_azucar <- crops2018%>%
filter(CULTIVO == "CAÑA AZUCARERA")
Creamos una nueva columna para guardar los datos de COD_MUN esta vez como objetos de tipo character:
caña_azucar$TEMP <- as.character(caña_azucar$COD_MUN)
Creamo suna nueva columna para guardar los datos anteriores, pero convirtiendolos en datos tipo factor:
caña_azucar$MPIO_CCDGO <- as.factor(paste(caña_azucar$TEMP, sep=""))
Usando la funcion \(left.join\) unimos los datos de nuestro interes.
caña_azucar_munic = left_join(vall_munic, caña_azucar, by="MPIO_CCDGO")
visualizamos el resultado de la union de datos anterior.
head(caña_azucar_munic)
asignamos un sistema de coordanadas a los datos, en este caso usamos el CRS:3116 el cual hace referencia a la zona de la capital Bogota.
rep_caña_azucar <- st_transform(caña_azucar_munic, crs= 3116)
Primero observaos el tipo de dato de las columnas que nos interesan.
class(rep_caña_azucar$produccion)
## [1] "NULL"
Observamos que nos arroja un tipo Nulo por lo cual usando la funcion \(as.numeric\) los convertimos a datos tipo numerico.
rep_caña_azucar$Produccion <- as.numeric(rep_caña_azucar$Produccion)
rep_caña_azucar$Rendimiento <- as.numeric(rep_caña_azucar$Rendimiento)
Observamos los primeros atributos de l objeto rep_caña_azucar.
head(rep_caña_azucar)
Ploteamos el mapa tematico usando como variables los datos Producicon y Rendimiento.
Usando la funcoin png guardamos el mapa en una ruta especifica.
png("C:/Users/JUANPABLO/Documents/R/GB/Datos/caña_azucar_2018.png", width = 2048, height = 1526)
opar <- par(mar = c(0,0,5,5))
plot(st_geometry(rep_caña_azucar), col="darkseagreen3", border="darkseagreen4",
bg = "white", lwd = 0.6)
propSymbolsChoroLayer(x = rep_caña_azucar, var = "Produccion", var2 = "Rendimiento",
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 = "Caña Production in 2018",
legend.var.style = "e")
labelLayer(
x = rep_caña_azucar,
txt = "MPIO_CNMBR",
col= "white",
cex = 1.0,
font = 4,
halo = FALSE,
bg = "white",
r = 0.1,
overlap = FALSE,
show.lines = FALSE
)
layoutLayer(title="Produccion y Rendimiendo de Caña de Azucar en Valle, 2018",
author = "Juan Cañon",
sources = "Sources: MADR & DANE, 2018",
scale = 50, tabtitle = FALSE, frame = TRUE)
north(pos = "topleft")
title(main="Producción y Rendimiendo de Caña de Azucar in Valle del Cauca, 2018", cex.main=3,
sub= "Source: MADR & DANE, 2018", cex.sub=2)
graticule = TRUE
par(opar)
dev.off()
## png
## 2
Por ultimo observamos el mapa que guardamos ateriormente con los datos
#knitr::include_graphics("C:/Users/JUANPABLO/Documents/R/GB/Datos/caña_azucar_2018.png")
sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 8.1 x64 (build 9600)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
## [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
## [5] LC_TIME=Spanish_Spain.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] RColorBrewer_1.1-2 rgdal_1.5-17 SpatialPosition_2.0.1
## [4] cartography_2.4.2 sf_0.9-6 raster_3.3-13
## [7] rgeos_0.5-5 readxl_1.3.1 sp_1.4-2
## [10] forcats_0.5.0 stringr_1.4.0 dplyr_1.0.2
## [13] purrr_0.3.4 readr_1.3.1 tidyr_1.1.2
## [16] tibble_3.0.3 ggplot2_3.3.2 tidyverse_1.3.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.5 lubridate_1.7.9 lattice_0.20-41 png_0.1-7
## [5] class_7.3-17 assertthat_0.2.1 digest_0.6.25 R6_2.4.1
## [9] cellranger_1.1.0 backports_1.1.10 reprex_0.3.0 evaluate_0.14
## [13] e1071_1.7-3 httr_1.4.2 pillar_1.4.6 rlang_0.4.7
## [17] rstudioapi_0.11 blob_1.2.1 rmarkdown_2.4 munsell_0.5.0
## [21] broom_0.7.0 compiler_4.0.2 modelr_0.1.8 xfun_0.17
## [25] pkgconfig_2.0.3 htmltools_0.5.0 tidyselect_1.1.0 codetools_0.2-16
## [29] fansi_0.4.1 crayon_1.3.4 dbplyr_1.4.4 withr_2.3.0
## [33] grid_4.0.2 lwgeom_0.2-5 jsonlite_1.7.1 gtable_0.3.0
## [37] lifecycle_0.2.0 DBI_1.1.0 magrittr_1.5 units_0.6-7
## [41] scales_1.1.1 KernSmooth_2.23-17 cli_2.0.2 stringi_1.5.3
## [45] fs_1.5.0 xml2_1.3.2 ellipsis_0.3.1 generics_0.0.2
## [49] vctrs_0.3.4 tools_4.0.2 glue_1.4.2 hms_0.5.3
## [53] slippymath_0.3.1 yaml_2.2.1 colorspace_1.4-1 isoband_0.2.2
## [57] classInt_0.4-3 rvest_0.3.6 knitr_1.30 haven_2.3.1