El propósito es mostrar las aplicaciones de los datos espaciales utilizando el programa R Package y R Studio, para generar y presentar los mapas temÔticos, aplicando algunas librerías que permiten el uso de los datos vectoriales, donde se indica los pasos a seguir desde el proceso de importación de los datos vectoriales, y desde excel, el proceso de join to relation, y las pautas para presentar los mapas de coropletas, los mapas de símbolos proporcionales y los mapas de contorno. AdemÔs, este documento tiene como objetivo ser una guía a los estudiantes del programa de ingeniería en Topografía y en el nivel tecnológico del mismo, en el curso de cartografía digital.

Los datos que se utilizaron para este ejercicio fueron datos de límite de departamentos de Colombia y los datos de estadísticos de personas afectadas por el Virus CORONAVIRUS (COVID-19) en Colombia, a la fecha de mes de noviembre del 2020, Publicado por el Ministerio de Salud y Protección Social https://www.minsalud.gov.co/salud/publica/PET/Paginas/Covid-19_copia.aspx,

La referencia utilizada para este proceso fue https://rpubs.com/ials2un/cartografia2.

Previamente cargamos las siguintes librerias.

library(rgdal)
## Loading required package: sp
## rgdal: version: 1.4-8, (SVN revision 845)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
##  Path to GDAL shared files: C:/Users/Usuario/Documents/R/win-library/3.6/rgdal/gdal
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
##  Path to PROJ.4 shared files: C:/Users/Usuario/Documents/R/win-library/3.6/rgdal/proj
##  Linking to sp version: 1.4-1
library(sp)
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(ggplot2)
library(knitr)
library(readxl)
library(rgeos)
## rgeos version: 0.5-2, (SVN revision 621)
##  GEOS runtime version: 3.6.1-CAPI-1.10.1 
##  Linking to sp version: 1.3-2 
##  Polygon checking: TRUE
library(cartography)
library(SpatialPosition)

Previamente cargamos la libreria.

library("readxl")

Luego importamos los datos desde excel

nbi_santander <- read_excel("C:/Users/Usuario/Desktop/Nueva carpeta (2)/nbi_santander.xlsx")

nbi_santander
## # A tibble: 33 x 14
##    Cod_dep NDep  `NBI%` pmiseria Cvivienda Cservicios Chacinamiento
##    <chr>   <chr>  <dbl>    <dbl>     <dbl>      <dbl>         <dbl>
##  1 05      Anti…  10.7     2.48      3.53       1.89           2.73
##  2 08      AtlÔ…  11.3     2.16      2.16       1.49           4.01
##  3 11      Bogo…   3.36    0.240     0.364      0.103          1.35
##  4 13      Bolí…  26.6     8.02     13.2        9.55           4.68
##  5 15      Boya…  10.0     1.89      2.33       1.80           3.13
##  6 17      Cald…   8.91    1.52      1.74       1.55           2.04
##  7 18      Caqu…  23.5     6.16     10.1        5.91           4.61
##  8 19      Cauca  18.3     3.15      5.99       5.87           3.71
##  9 20      Cesar  22.8     7.17      9.31       5.04           7.88
## 10 23      Córd…  34.8    11.2      26.0        6.16           6.90
## # … with 23 more rows, and 7 more variables: Cinasistencia <dbl>,
## #   Cdeconómica <dbl>, cnuevos <dbl>, ctotales <dbl>, recuperados <dbl>,
## #   fallecidos <dbl>, hospitalizados <dbl>
nbi_santander$Cod_dep
##  [1] "05" "08" "11" "13" "15" "17" "18" "19" "20" "23" "25" "27" "41" "44" "47"
## [16] "50" "52" "54" "63" "66" "68" "70" "73" "76" "81" "85" "86" "88" "91" "94"
## [31] "95" "97" "99"

Luego importamos los datos vectoriales a R

dep <- st_read("E:/A_UTS/2020 -II/Docencia/Cartografia digital/11 Elaboracion de mapas tematicos/Datos taller/shape/departamentos.shp")
## Reading layer `departamentos' from data source `E:\A_UTS\2020 -II\Docencia\Cartografia digital\11 Elaboracion de mapas tematicos\Datos taller\shape\departamentos.shp' using driver `ESRI Shapefile'
## Simple feature collection with 33 features and 11 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -81.73562 ymin: -4.23285 xmax: -66.84722 ymax: 13.39473
## geographic CRS: WGS 84
dep
## Simple feature collection with 33 features and 11 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -81.73562 ymin: -4.23285 xmax: -66.84722 ymax: 13.39473
## geographic CRS: WGS 84
## First 10 features:
##    OBJECTID DPTO_CCDGO DPTO_NANO_   DPTO_CNMBR
## 1        34         05       1886    ANTIOQUIA
## 2        35         08       1910    ATLƁNTICO
## 3        36         11       1538 BOGOTƁ, D.C.
## 4        37         13       1886      BOLƍVAR
## 5        38         15       1886       BOYACƁ
## 6        39         17       1905       CALDAS
## 7        40         18       1981      CAQUETƁ
## 8        41         19       1857        CAUCA
## 9        42         20       1967        CESAR
## 10       43         23       1951      CƓRDOBA
##                            DPTO_CACTO DPTO_NAREA DPTO_CSMBL DPTO_NANO
## 1       Constitucion Politica de 1886  62967.722          3      2016
## 2                      Ley 21 de 1910   3315.752          3      2016
## 3       Constitucion Politica de 1886   1622.739          3      2016
## 4       Constitucion Politica de 1886  26689.691          3      2016
## 5       Constitucion Politica de 1886  23138.048          3      2016
## 6                 11 de Abril de 1905   7425.270          3      2016
## 7  Ley 78 del 29 de Diciembre de 1981  90103.008          3      2016
## 8                 15 de junio de 1857  31242.951          3      2016
## 9         Ley 25  21 de junio de 1967  22562.360          3      2016
## 10  Ley 9 del 18 de Diciembre de 1951  25086.368          3      2016
##    SHAPE_Leng SHAPE_Area REVISADO                       geometry
## 1   21.519802  5.1482305        * MULTIPOLYGON (((-76.4136 8....
## 2    2.540766  0.2739304        1 MULTIPOLYGON (((-74.84946 1...
## 3    3.751874  0.1321986        2 MULTIPOLYGON (((-74.07419 4...
## 4   15.175668  2.1931451        * MULTIPOLYGON (((-75.25555 1...
## 5   15.906491  1.8883908        * MULTIPOLYGON (((-72.17368 7...
## 6    6.656352  0.6055017        * MULTIPOLYGON (((-74.67154 5...
## 7   21.384287  7.3184847        6 MULTIPOLYGON (((-74.89423 2...
## 8   13.951565  2.5344218        8 MULTIPOLYGON (((-76.45922 3...
## 9   12.609051  1.8579611        * MULTIPOLYGON (((-73.45374 1...
## 10   9.687635  2.0575255        * MULTIPOLYGON (((-75.91797 9...
class(dep)
## [1] "sf"         "data.frame"

ejecutamos el proceso de join to relation,

cant <- merge(dep, nbi_santander,by.x="DPTO_CCDGO",by.y="Cod_dep")
summary(cant)
##    DPTO_CCDGO    OBJECTID    DPTO_NANO_  
##  05     : 1   Min.   :34   Min.   :1538  
##  08     : 1   1st Qu.:42   1st Qu.:1905  
##  11     : 1   Median :50   Median :1959  
##  13     : 1   Mean   :50   Mean   :1932  
##  15     : 1   3rd Qu.:58   3rd Qu.:1991  
##  17     : 1   Max.   :66   Max.   :1991  
##  (Other):27                              
##                                                     DPTO_CNMBR
##  AMAZONAS                                                : 1  
##  ANTIOQUIA                                               : 1  
##  ARAUCA                                                  : 1  
##  ARCHIPIƉLAGO DE SAN ANDRƉS, PROVIDENCIA Y SANTA CATALINA: 1  
##  ATLƁNTICO                                               : 1  
##  BOGOTƁ, D.C.                                            : 1  
##  (Other)                                                 :27  
##                                       DPTO_CACTO   DPTO_NAREA       DPTO_CSMBL
##  Constitucion Politica de 1886             : 5   Min.   :    49.4   3:33      
##  5 de Julio Constitucion Politica de 1991  : 4   1st Qu.: 20619.7             
##  Articulo 309 Constitucion Politica de 1991: 3   Median : 24139.4             
##  11 de Abril de 1905                       : 1   Mean   : 34573.8             
##  15 de junio de 1857                       : 1   3rd Qu.: 48188.4             
##  1964                                      : 1   Max.   :109497.6             
##  (Other)                                   :18                                
##    DPTO_NANO      SHAPE_Leng        SHAPE_Area          REVISADO 
##  Min.   :2016   Min.   : 0.6736   Min.   :0.004048   *      :18  
##  1st Qu.:2016   1st Qu.: 9.5509   1st Qu.:1.679404   1      : 3  
##  Median :2016   Median :12.5654   Median :1.965024   4      : 2  
##  Mean   :2016   Mean   :12.6862   Mean   :2.813048   2      : 1  
##  3rd Qu.:2016   3rd Qu.:17.2926   3rd Qu.:3.926268   3      : 1  
##  Max.   :2016   Max.   :25.3659   Max.   :8.877540   (Other): 3  
##                                                      NA's   : 5  
##      NDep                NBI%           pmiseria         Cvivienda      
##  Length:33          Min.   : 3.356   Min.   : 0.2397   Min.   : 0.3636  
##  Class :character   1st Qu.:10.673   1st Qu.: 1.8898   1st Qu.: 2.3348  
##  Mode  :character   Median :18.270   Median : 3.6077   Median : 5.7172  
##                     Mean   :24.200   Mean   : 9.0704   Mean   :10.7145  
##                     3rd Qu.:28.981   3rd Qu.: 8.9695   3rd Qu.:13.1605  
##                     Max.   :68.888   Max.   :50.6757   Max.   :56.5885  
##                                                                         
##    Cservicios      Chacinamiento    Cinasistencia    Cdeconómica     
##  Min.   : 0.1031   Min.   : 1.335   Min.   :1.007   Min.   : 0.3784  
##  1st Qu.: 1.5540   1st Qu.: 2.726   1st Qu.:1.532   1st Qu.: 4.1274  
##  Median : 4.4646   Median : 4.681   Median :1.843   Median : 5.1363  
##  Mean   :10.3564   Mean   : 7.852   Mean   :2.773   Mean   : 6.3785  
##  3rd Qu.: 9.5473   3rd Qu.: 7.636   3rd Qu.:3.090   3rd Qu.: 7.5948  
##  Max.   :57.4218   Max.   :33.205   Max.   :9.757   Max.   :17.8814  
##                                                                      
##     cnuevos          ctotales       recuperados       fallecidos    
##  Min.   :   0.0   Min.   :   846   Min.   :   816   Min.   :  11.0  
##  1st Qu.:  11.0   1st Qu.:  4572   1st Qu.:  4126   1st Qu.: 163.0  
##  Median :  68.0   Median : 15925   Median : 14369   Median : 425.0  
##  Mean   : 150.7   Mean   : 33266   Mean   : 29400   Mean   : 914.6  
##  3rd Qu.: 176.0   3rd Qu.: 26007   3rd Qu.: 23494   3rd Qu.: 847.0  
##  Max.   :1573.0   Max.   :366585   Max.   :304856   Max.   :7917.0  
##                                                                     
##  hospitalizados            geometry 
##  Min.   :   0.0   MULTIPOLYGON :33  
##  1st Qu.:  97.0   epsg:4326    : 0  
##  Median : 361.0   +proj=long...: 0  
##  Mean   : 912.2                     
##  3rd Qu.: 805.0                     
##  Max.   :6183.0                     
## 

En seguida cargamos la libreria

library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
mun.osm <- getTiles(
  x = cant, 
  type = "OpenStreetMap", 
  zoom = 6,
  cachedir = TRUE,
  crop = FALSE
)

Para establecer margenes, mostrar los bordes de los limites de los departamentos y

opar <- par(mar = c(0,0,2,0))


tilesLayer(x = mun.osm)

plot(st_geometry(cant), col = NA, border = "red", add=TRUE)

# Para presentar en el mapa la cantidad de nuevos casos (simbolos proporcionales) 
propSymbolsLayer(
  x = cant, 
  var = "cnuevos", 
  inches = 0.12, 
  col = "lightblue",
  legend.pos = "topright",  
  legend.title.txt = "Cantidad de nuevos casos"
)
## Warning in st_centroid.sfc(x = sf::st_geometry(x), of_largest_polygon =
## max(sf::st_is(sf::st_as_sf(x), : st_centroid does not give correct centroids for
## longitude/latitude data
# uso de layout
layoutLayer(title = " Mapa cantidad nuevos casos COVID",
            sources = "Fuente: Minsalud  nov. 2020\n© OpenStreetMap",
            author = " Aponte Saravia ",
            frame = TRUE, north = FALSE, tabtitle = TRUE)

# Para insertar el norte magnetico.
north(pos = "topleft")

Parte 2: Mapa de coropletas

# Margenes
opar <- par(mar = c(0,0,1,0))
# color del  background
par(bg="grey90")
# plotear Departamentos 
plot(st_geometry(cant), col = NA, border = "blue", bg = "#aadaff")


# Ploter la cantidad de fallecidos 
choroLayer(
  x = cant, 
  var = "fallecidos",
  method = "geom",
  nclass=8,
  col = carto.pal(pal1 = "sand.pal", n1 = 10),
  border = "red", 
  lwd = 0.5,
  legend.pos = "topleft", 
  legend.title.txt = "Cantidad de fallecidos",
  add = TRUE
) 

propSymbolsLayer(
  x = cant, 
  var = "cnuevos", 
  inches = 0.15, 
  col = "lightblue",
  legend.pos = "topright",  
  legend.title.txt = "Cantidad de nuevos casos"
)
## Warning in st_centroid.sfc(x = sf::st_geometry(x), of_largest_polygon =
## max(sf::st_is(sf::st_as_sf(x), : st_centroid does not give correct centroids for
## longitude/latitude data
# layout
layoutLayer(title = "Fallecidos y nuevos casos  por covid", 
            sources = "Minsalud, 2020",
            author = "Aponte Saravia", 
            frame = TRUE, north = FALSE, tabtitle = TRUE, col="black")

north(pos = "topright")

Parte 3: Mapas de coropletas con etiquetado.

#
opar <- par(mar = c(0,0,1,0))
#
tilesLayer(x = mun.osm)

# plotear los bordes de los departamentos 
plot(st_geometry(cant), col = NA, border = "red", add=TRUE)
#
choroLayer(
  x = cant, 
  var = "fallecidos",
  method = "geom",
  nclass=5,
  col = carto.pal(pal1 = "sand.pal", n1 = 10),
  border = "white", 
  lwd = 0.5,
  legend.pos = "topright", 
  legend.title.txt = "Fallecidos covid",
  add = TRUE
) 


labelLayer(
  x = cant, 
  txt = "DPTO_CNMBR", 
  col= "white", 
  cex = 0.4, 
  font = 4,
  halo = TRUE, 
  bg = "grey25", 
  r = 0.1, 
  overlap = FALSE, 
  show.lines = FALSE
)
## Warning in st_centroid.sfc(x = sf::st_geometry(x), of_largest_polygon =
## max(sf::st_is(sf::st_as_sf(x), : st_centroid does not give correct centroids for
## longitude/latitude data
layoutLayer(
  title = "Fallecidos covid 2020 ", 
  sources = "Minsalud, nov. 2020",  
  author = "Aponte Saravia", 
  frame = TRUE,
  north = FALSE, 
  tabtitle = TRUE, 
  theme = "taupe.pal"
) 
#
north(pos = "topleft")

Parte 4: Mapas de contorno.

opar <- par(mar = c(0,0,1.2,0))

plot(st_geometry(cant), col = NA, border = "black", bg = "grey75")

smoothLayer(
  x = cant, 
  var = 'cnuevos',
  typefct = "exponential",
  span = 20000,
  beta = 2,
  nclass = 10,
  col = carto.pal(pal1 = 'harmo.pal', n1 = 10),
  border = "grey",
  lwd = 0.1, 
  mask = cant, 
  legend.values.rnd = -3,
  legend.title.txt = "Nuevos casos",
  legend.pos = "right", 
  add=TRUE)
## Warning in st_centroid.sfc(st_geometry(knownpts), of_largest_polygon =
## all(st_is(knownpts, : st_centroid does not give correct centroids for longitude/
## latitude data
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
text(x = 650000, y = 1200000, cex = 0.6, adj = 0, font = 3, labels = "Función distancia:\n- type = exponential\n- beta = 2\n- span = 50 km")

layoutLayer(
  title = "Nuevos casos covid", 
  sources = "Minsalud, 2020",  
  author = "Aponte Saravia", 
  frame = TRUE,
  north = FALSE, 
  tabtitle = TRUE, 
  theme = "taupe.pal"
) 
north(pos = "topleft")