El siguiente cuaderno tiene como objetivo ilustrar funciones geospaciales básicas de R, las cuales se encuentran en las librerías de simple features (sf) y tidyverse.
Luego de tener las librerías descargadas es necesario llamarlas de la siguiente forma:
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(tidyverse)
## -- Attaching packages ------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.2 v dplyr 1.0.0
## v tidyr 1.1.0 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()
Inicialmente se debe ubicar el directorio de trabajo y cambiarlo de ser necesario. A continuación se debe descargar un archivo de tipo shapefile de DIVA-GIS del departamento o lugar de interés, en este caso será el departamento de Cesár. Posteriormente, se debe subir el archivo shapefile a R usando el código:
getwd()
## [1] "C:/Users/JUAN PABLO/Downloads"
setwd("C:/Users/JUAN PABLO/Documents/geo maps")
getwd()
## [1] "C:/Users/JUAN PABLO/Downloads"
Deptos <- read_sf("C:/Users/JUAN PABLO/Documents/geo maps/COL_adm1.shp")
Para conocer los datos que contiene el archivo se usa la función head
head(Deptos)
A continuación, para conocer el sistema de referencia que tienen los datos se debe usar el comando “st_crs” de la libería sf
st_crs(Deptos)
## Coordinate Reference System:
## User input: WGS 84
## wkt:
## GEOGCRS["WGS 84",
## DATUM["World Geodetic System 1984",
## ELLIPSOID["WGS 84",6378137,298.257223563,
## LENGTHUNIT["metre",1]]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## CS[ellipsoidal,2],
## AXIS["latitude",north,
## ORDER[1],
## ANGLEUNIT["degree",0.0174532925199433]],
## AXIS["longitude",east,
## ORDER[2],
## ANGLEUNIT["degree",0.0174532925199433]],
## ID["EPSG",4326]]
De acuerdo con lo anterior, los datos utilizan el Sistema Geodésico Mundial de 1984 (WGS 84).
Para visualizar los datos que se acaban de subir a R se emplea la función:
ggplot() + geom_sf(data = Deptos, fill= "mediumorchid1")
Es posible usar cualquier sistema de referencia además del WGS 84 de la siguiente forma:
ggplot() + geom_sf(data = Deptos, fill= "mediumpurple") + coord_sf(crs=st_crs(3978))
Para transformar al sistema de coordenadas UTM 18 N, se emplea el código 32168 de la siguiente forma:
Deptos_UTM <- st_transform(Deptos, crs = st_crs(32618))
Para visualizar cómo quedó la transformación es necesario llamar los datos
Deptos_UTM
Se grafica los datos luego de ser transformados, tal como se realizó previamente
ggplot() + geom_sf(data = Deptos_UTM, fill= "plum")
4. Filtrar datos geoespaciales de acuerdo a sus atributos
En caso de estar interesado en un solo departamento en específico, es necesario filtrar los datos para visualizar solo aquel departamento
Cesar <- Deptos %>% filter (NAME_1 == "Cesar")
Visualizar el departamento filtrado
ggplot() + geom_sf(data = Cesar, fill= "violet")
El mapa anterior muestra únicamente el departamento de Cesar. En caso de tener interes en los municipios de este departamento es posible visualizarlos subiendo previamente el segundo archivo descargado
Munic <- read_sf("C:/Users/JUAN PABLO/Documents/geo maps/COL_adm2.shp")
Mun_Cesar <- Munic %>% filter(NAME_1 == "Cesar")
ggplot() + geom_sf(data = Mun_Cesar, fill= "orchid")
Mun_Cesar
Cesar_points <- st_centroid(Mun_Cesar)
## Warning in st_centroid.sf(Mun_Cesar): st_centroid assumes attributes are
## constant over geometries of x
## Warning in st_centroid.sfc(st_geometry(x), of_largest_polygon =
## of_largest_polygon): st_centroid does not give correct centroids for longitude/
## latitude data
Cesar_points <- cbind(Mun_Cesar, st_coordinates(st_centroid(Mun_Cesar$geometry)))
## Warning in st_centroid.sfc(Mun_Cesar$geometry): st_centroid does not give
## correct centroids for longitude/latitude data
ggplot(Cesar) +
geom_sf() +
geom_sf(data = Cesar_points, fill = "pink") +
geom_text(data = Cesar_points, aes( x=X, y=Y, label = ID_2), size = 2)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
library(tidyverse)
ggplot(Cesar) +
geom_sf(data=Cesar_points, aes(x=X, y=Y, fill =
ID_2), color = "black", size = 0.25) +
geom_text(data = Cesar_points, aes(x=X, y=Y, label= ID_2), size = 2) +
theme(aspect.ratio=1)+
scale_fill_distiller(name="ID_2", palette= "RdPu", breaks = pretty_breaks(n = 5)) +
labs(title= "Cesar")
## Warning: Ignoring unknown aesthetics: x, y
Para guardar la imagen anterior como formato PDF o PNG se usa los siguientes comandos, respectivamente
ggsave("Cesar_municipios.pdf")
## Saving 7 x 5 in image
ggsave("Cesar_Municipios.png", width = 6, height = 6, dpi = "screen")
Luego de haber instalado la librería es necesario llamarla
library(leaflet)
Para poder usar la librería es necesario convertir los datos de objetos simples a puntos espaciales
Ces_points <- as(Cesar_points, "Spatial")
Para ver qué hay en el objeto acabo de crear:
head(Ces_points)
## An object of class "SpatialPolygonsDataFrame"
## Slot "data":
## ID_0 ISO NAME_0 ID_1 NAME_1 ID_2 NAME_2 TYPE_2 ENGTYPE_2
## 1 53 COL Colombia 12 Cesar 445 Aguachica Municipio Municipality
## 2 53 COL Colombia 12 Cesar 446 Agustín Codazzi Municipio Municipality
## 3 53 COL Colombia 12 Cesar 447 Astrea Municipio Municipality
## 4 53 COL Colombia 12 Cesar 448 Becerril Municipio Municipality
## 5 53 COL Colombia 12 Cesar 449 Bosconia Municipio Municipality
## 6 53 COL Colombia 12 Cesar 450 Chimichagua Municipio Municipality
## NL_NAME_2 VARNAME_2 X Y
## 1 <NA> <NA> -73.62440 8.243963
## 2 <NA> <NA> -73.26192 9.932845
## 3 <NA> <NA> -73.97883 9.489856
## 4 <NA> <NA> -73.21746 9.742881
## 5 <NA> <NA> -73.88857 9.929217
## 6 <NA> <NA> -73.77037 9.219282
##
## Slot "polygons":
## [[1]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.624398 8.243963
##
## Slot "area":
## [1] 0.07514397
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.48020 8.307100
## [2,] -73.47730 8.290900
## [3,] -73.47840 8.266100
## [4,] -73.47840 8.249301
## [5,] -73.48010 8.233698
## [6,] -73.50200 8.218799
## [7,] -73.52400 8.227000
## [8,] -73.53840 8.231701
## [9,] -73.56080 8.223100
## [10,] -73.57410 8.208700
## [11,] -73.58790 8.193200
## [12,] -73.59080 8.171199
## [13,] -73.59890 8.161401
## [14,] -73.60000 8.152201
## [15,] -73.58960 8.130800
## [16,] -73.58270 8.118602
## [17,] -73.58670 8.106499
## [18,] -73.61550 8.096200
## [19,] -73.63690 8.092300
## [20,] -73.64380 8.089401
## [21,] -73.64840 8.077901
## [22,] -73.63680 8.046100
## [23,] -73.62880 8.022901
## [24,] -73.63620 8.023500
## [25,] -73.66330 8.022502
## [26,] -73.68180 8.008100
## [27,] -73.71920 8.005399
## [28,] -73.75560 7.997500
## [29,] -73.75900 8.005602
## [30,] -73.76590 8.013700
## [31,] -73.76940 8.027001
## [32,] -73.77170 8.032799
## [33,] -73.77580 8.043800
## [34,] -73.78610 8.055401
## [35,] -73.79590 8.066400
## [36,] -73.80060 8.071002
## [37,] -73.79600 8.083701
## [38,] -73.78850 8.107899
## [39,] -73.78850 8.116601
## [40,] -73.79600 8.113200
## [41,] -73.80014 8.115026
## [42,] -73.80760 8.118317
## [43,] -73.80920 8.126501
## [44,] -73.80060 8.130501
## [45,] -73.77230 8.124600
## [46,] -73.76140 8.135602
## [47,] -73.75510 8.143000
## [48,] -73.73890 8.163799
## [49,] -73.73610 8.175901
## [50,] -73.72110 8.178700
## [51,] -73.70380 8.178600
## [52,] -73.69280 8.183201
## [53,] -73.69230 8.188400
## [54,] -73.69980 8.205801
## [55,] -73.70670 8.223100
## [56,] -73.70840 8.235799
## [57,] -73.69810 8.255999
## [58,] -73.68940 8.269799
## [59,] -73.67910 8.281899
## [60,] -73.66930 8.298601
## [61,] -73.66010 8.325201
## [62,] -73.65080 8.343001
## [63,] -73.64910 8.362100
## [64,] -73.64910 8.370200
## [65,] -73.64280 8.374202
## [66,] -73.63360 8.375900
## [67,] -73.63590 8.386901
## [68,] -73.63700 8.396702
## [69,] -73.64110 8.415801
## [70,] -73.64220 8.430200
## [71,] -73.64510 8.442900
## [72,] -73.65030 8.463200
## [73,] -73.64340 8.464900
## [74,] -73.63070 8.465402
## [75,] -73.61290 8.467100
## [76,] -73.60130 8.468800
## [77,] -73.59150 8.473901
## [78,] -73.58460 8.484300
## [79,] -73.57940 8.493501
## [80,] -73.57140 8.496899
## [81,] -73.55083 8.506720
## [82,] -73.55060 8.502599
## [83,] -73.54080 8.499099
## [84,] -73.52870 8.494401
## [85,] -73.52640 8.478801
## [86,] -73.52240 8.470701
## [87,] -73.51080 8.468401
## [88,] -73.50850 8.469500
## [89,] -73.50050 8.475799
## [90,] -73.49640 8.479899
## [91,] -73.48890 8.471699
## [92,] -73.49470 8.460800
## [93,] -73.49640 8.450400
## [94,] -73.49640 8.440600
## [95,] -73.49350 8.430800
## [96,] -73.49410 8.421501
## [97,] -73.49470 8.417499
## [98,] -73.49750 8.412300
## [99,] -73.50100 8.402500
## [100,] -73.50560 8.396100
## [101,] -73.51080 8.388700
## [102,] -73.51420 8.380000
## [103,] -73.52350 8.370802
## [104,] -73.52120 8.361001
## [105,] -73.51190 8.352899
## [106,] -73.50330 8.346501
## [107,] -73.49350 8.338901
## [108,] -73.49170 8.328499
## [109,] -73.48710 8.315799
## [110,] -73.48020 8.307100
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.624398 8.243963
##
## Slot "ID":
## [1] "1"
##
## Slot "area":
## [1] 0.07514397
##
##
## [[2]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.261924 9.932845
##
## Slot "area":
## [1] 0.1356965
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -72.95625 10.013630
## [2,] -73.01650 9.960002
## [3,] -73.02800 9.952000
## [4,] -73.04650 9.943401
## [5,] -73.07930 9.923299
## [6,] -73.08860 9.920500
## [7,] -73.09830 9.917599
## [8,] -73.11050 9.912500
## [9,] -73.11850 9.905000
## [10,] -73.12080 9.888799
## [11,] -73.13060 9.869801
## [12,] -73.13920 9.861801
## [13,] -73.16000 9.850900
## [14,] -73.19000 9.842301
## [15,] -73.20960 9.836099
## [16,] -73.23150 9.831001
## [17,] -73.25620 9.825300
## [18,] -73.27930 9.820202
## [19,] -73.31330 9.808799
## [20,] -73.33580 9.802500
## [21,] -73.36750 9.796301
## [22,] -73.38940 9.788900
## [23,] -73.40550 9.783200
## [24,] -73.42680 9.776301
## [25,] -73.45340 9.768400
## [26,] -73.47350 9.756901
## [27,] -73.49140 9.749501
## [28,] -73.50810 9.743201
## [29,] -73.52310 9.726500
## [30,] -73.53170 9.711501
## [31,] -73.53580 9.699401
## [32,] -73.54040 9.686100
## [33,] -73.55190 9.677501
## [34,] -73.56050 9.661900
## [35,] -73.56280 9.645201
## [36,] -73.55300 9.641101
## [37,] -73.55650 9.638799
## [38,] -73.57490 9.638899
## [39,] -73.61120 9.639599
## [40,] -73.63780 9.640298
## [41,] -73.65850 9.648501
## [42,] -73.65790 9.666999
## [43,] -73.65560 9.683101
## [44,] -73.64410 9.703301
## [45,] -73.64760 9.725900
## [46,] -73.63490 9.735600
## [47,] -73.62970 9.744300
## [48,] -73.62230 9.752300
## [49,] -73.61020 9.762702
## [50,] -73.59630 9.775301
## [51,] -73.57390 9.800601
## [52,] -73.54100 9.830000
## [53,] -73.51340 9.852898
## [54,] -73.48170 9.869001
## [55,] -73.47070 9.894901
## [56,] -73.46900 9.920901
## [57,] -73.46960 9.945201
## [58,] -73.46730 9.953301
## [59,] -73.45870 9.964200
## [60,] -73.43270 9.973301
## [61,] -73.41140 9.985902
## [62,] -73.39930 10.003800
## [63,] -73.39070 10.022298
## [64,] -73.36420 10.030801
## [65,] -73.33250 10.036401
## [66,] -73.31000 10.035202
## [67,] -73.28920 10.031601
## [68,] -73.27140 10.031601
## [69,] -73.25290 10.031501
## [70,] -73.24020 10.032000
## [71,] -73.22240 10.034799
## [72,] -73.19760 10.039902
## [73,] -73.17970 10.046199
## [74,] -73.16760 10.062900
## [75,] -73.16070 10.069200
## [76,] -73.15260 10.070401
## [77,] -73.13760 10.072600
## [78,] -73.12500 10.074298
## [79,] -73.11290 10.082902
## [80,] -73.09790 10.096700
## [81,] -73.08000 10.109299
## [82,] -73.04430 10.139201
## [83,] -72.99990 10.171401
## [84,] -72.95960 10.207001
## [85,] -72.90305 10.257356
## [86,] -72.90227 10.252032
## [87,] -72.90438 10.233897
## [88,] -72.89888 10.212890
## [89,] -72.90147 10.209709
## [90,] -72.90754 10.207498
## [91,] -72.90889 10.194179
## [92,] -72.90939 10.175102
## [93,] -72.91611 10.158640
## [94,] -72.91845 10.141660
## [95,] -72.91698 10.130372
## [96,] -72.91404 10.108716
## [97,] -72.92067 10.099152
## [98,] -72.92710 10.086829
## [99,] -72.94760 10.063440
## [100,] -72.95364 10.046744
## [101,] -72.95061 10.030835
## [102,] -72.95233 10.023731
## [103,] -72.95625 10.013630
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.261924 9.932845
##
## Slot "ID":
## [1] "2"
##
## Slot "area":
## [1] 0.1356965
##
##
## [[3]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.978834 9.489856
##
## Slot "area":
## [1] 0.04712278
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.80720 9.510502
## [2,] -73.81520 9.496100
## [3,] -73.83940 9.477700
## [4,] -73.84750 9.465600
## [5,] -73.86070 9.456402
## [6,] -73.87690 9.450699
## [7,] -73.88840 9.450802
## [8,] -73.89470 9.453701
## [9,] -73.90510 9.458300
## [10,] -73.92240 9.454900
## [11,] -73.93450 9.446301
## [12,] -73.94780 9.429597
## [13,] -73.94660 9.421499
## [14,] -73.95240 9.408301
## [15,] -73.96730 9.386400
## [16,] -73.96790 9.374301
## [17,] -73.97540 9.352300
## [18,] -73.98110 9.339102
## [19,] -73.99840 9.333401
## [20,] -73.99960 9.344401
## [21,] -74.01060 9.353699
## [22,] -74.01800 9.358900
## [23,] -74.02840 9.368199
## [24,] -74.03420 9.372801
## [25,] -74.04110 9.378000
## [26,] -74.04630 9.387298
## [27,] -74.06250 9.405299
## [28,] -74.07520 9.418600
## [29,] -74.08610 9.431901
## [30,] -74.10170 9.444101
## [31,] -74.14840 9.466902
## [32,] -74.15633 9.477103
## [33,] -74.15470 9.483599
## [34,] -74.14780 9.487701
## [35,] -74.13690 9.495701
## [36,] -74.12770 9.500300
## [37,] -74.11960 9.507801
## [38,] -74.10810 9.522700
## [39,] -74.08620 9.545701
## [40,] -74.07580 9.561301
## [41,] -74.05330 9.582000
## [42,] -74.01700 9.582399
## [43,] -73.99400 9.575999
## [44,] -73.97380 9.575300
## [45,] -73.95820 9.575202
## [46,] -73.93570 9.576300
## [47,] -73.89420 9.580200
## [48,] -73.86080 9.580601
## [49,] -73.85040 9.574199
## [50,] -73.82280 9.572401
## [51,] -73.81010 9.546899
## [52,] -73.81060 9.534800
## [53,] -73.81000 9.520901
## [54,] -73.80720 9.510502
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.978834 9.489856
##
## Slot "ID":
## [1] "3"
##
## Slot "area":
## [1] 0.04712278
##
##
## [[4]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.217461 9.742881
##
## Slot "area":
## [1] 0.1151246
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -72.95625 10.013630
## [2,] -72.95907 10.006353
## [3,] -72.96041 10.000001
## [4,] -72.96081 9.998100
## [5,] -72.97114 9.988591
## [6,] -72.97757 9.976038
## [7,] -72.97917 9.960886
## [8,] -72.98707 9.943066
## [9,] -72.98959 9.928616
## [10,] -72.98951 9.917578
## [11,] -72.98638 9.909027
## [12,] -72.98558 9.899819
## [13,] -72.98058 9.892852
## [14,] -72.99045 9.882874
## [15,] -72.98360 9.875879
## [16,] -72.97874 9.875120
## [17,] -72.96613 9.865744
## [18,] -72.95698 9.857564
## [19,] -72.95032 9.853559
## [20,] -72.94694 9.847073
## [21,] -72.94772 9.840188
## [22,] -72.95883 9.824487
## [23,] -72.96332 9.818342
## [24,] -72.96895 9.813132
## [25,] -72.98583 9.798432
## [26,] -72.99506 9.784080
## [27,] -73.00190 9.758889
## [28,] -73.00627 9.744238
## [29,] -73.01943 9.730169
## [30,] -73.03722 9.699845
## [31,] -73.04992 9.684621
## [32,] -73.05591 9.669993
## [33,] -73.05829 9.654383
## [34,] -73.07920 9.650099
## [35,] -73.09070 9.643801
## [36,] -73.10110 9.637500
## [37,] -73.11610 9.628900
## [38,] -73.13510 9.617400
## [39,] -73.15520 9.610601
## [40,] -73.16620 9.610000
## [41,] -73.18180 9.605501
## [42,] -73.19560 9.600302
## [43,] -73.20830 9.603301
## [44,] -73.21580 9.603301
## [45,] -73.23250 9.595899
## [46,] -73.24690 9.585499
## [47,] -73.26880 9.580400
## [48,] -73.28780 9.582301
## [49,] -73.30160 9.582901
## [50,] -73.32410 9.580701
## [51,] -73.35240 9.587101
## [52,] -73.36680 9.588400
## [53,] -73.38120 9.594800
## [54,] -73.38810 9.606399
## [55,] -73.39620 9.621999
## [56,] -73.41410 9.634202
## [57,] -73.43200 9.641201
## [58,] -73.44520 9.648200
## [59,] -73.45440 9.659199
## [60,] -73.46370 9.674800
## [61,] -73.47640 9.674900
## [62,] -73.48500 9.672601
## [63,] -73.49080 9.670299
## [64,] -73.49830 9.667500
## [65,] -73.50460 9.665802
## [66,] -73.51320 9.659999
## [67,] -73.52190 9.658301
## [68,] -73.53170 9.645101
## [69,] -73.55300 9.641101
## [70,] -73.56280 9.645201
## [71,] -73.56050 9.661900
## [72,] -73.55190 9.677501
## [73,] -73.54040 9.686100
## [74,] -73.53580 9.699401
## [75,] -73.53170 9.711501
## [76,] -73.52310 9.726500
## [77,] -73.50810 9.743201
## [78,] -73.49140 9.749501
## [79,] -73.47350 9.756901
## [80,] -73.45340 9.768400
## [81,] -73.42680 9.776301
## [82,] -73.40550 9.783200
## [83,] -73.38940 9.788900
## [84,] -73.36750 9.796301
## [85,] -73.33580 9.802500
## [86,] -73.31330 9.808799
## [87,] -73.27930 9.820202
## [88,] -73.25620 9.825300
## [89,] -73.23150 9.831001
## [90,] -73.20960 9.836099
## [91,] -73.19000 9.842301
## [92,] -73.16000 9.850900
## [93,] -73.13920 9.861801
## [94,] -73.13060 9.869801
## [95,] -73.12080 9.888799
## [96,] -73.11850 9.905000
## [97,] -73.11050 9.912500
## [98,] -73.09830 9.917599
## [99,] -73.08860 9.920500
## [100,] -73.07930 9.923299
## [101,] -73.04650 9.943401
## [102,] -73.02800 9.952000
## [103,] -73.01650 9.960002
## [104,] -72.95625 10.013630
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.217461 9.742881
##
## Slot "ID":
## [1] "4"
##
## Slot "area":
## [1] 0.1151246
##
##
## [[5]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.888567 9.929217
##
## Slot "area":
## [1] 0.04892045
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.7618 9.846501
## [2,] -73.7768 9.844801
## [3,] -73.8016 9.828199
## [4,] -73.8160 9.814901
## [5,] -73.8287 9.804601
## [6,] -73.8413 9.797101
## [7,] -73.8742 9.781701
## [8,] -73.8765 9.784000
## [9,] -73.8799 9.789801
## [10,] -73.8817 9.791501
## [11,] -73.8857 9.796198
## [12,] -73.9117 9.811300
## [13,] -73.9255 9.823500
## [14,] -73.9365 9.842002
## [15,] -73.9515 9.864000
## [16,] -73.9596 9.885401
## [17,] -73.9867 9.911502
## [18,] -73.9999 9.916799
## [19,] -74.0230 9.931900
## [20,] -74.0316 9.949299
## [21,] -74.0316 9.957401
## [22,] -74.0518 9.973602
## [23,] -74.0645 9.985799
## [24,] -74.0167 10.004101
## [25,] -74.0155 10.015100
## [26,] -73.9936 10.023599
## [27,] -73.9666 10.036200
## [28,] -73.9470 10.037301
## [29,] -73.9245 10.040102
## [30,] -73.9008 10.043500
## [31,] -73.8772 10.046801
## [32,] -73.8507 10.059400
## [33,] -73.8513 10.054800
## [34,] -73.8530 10.049599
## [35,] -73.8547 10.036301
## [36,] -73.8518 10.030500
## [37,] -73.8368 10.029299
## [38,] -73.8190 10.026400
## [39,] -73.8080 10.019401
## [40,] -73.7976 10.002599
## [41,] -73.7942 9.983500
## [42,] -73.7803 9.949402
## [43,] -73.7595 9.898499
## [44,] -73.7520 9.883400
## [45,] -73.7486 9.867802
## [46,] -73.7532 9.848199
## [47,] -73.7618 9.846501
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.888567 9.929217
##
## Slot "ID":
## [1] "5"
##
## Slot "area":
## [1] 0.04892045
##
##
## [[6]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.770370 9.219282
##
## Slot "area":
## [1] 0.1214687
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.69730 9.019099
## [2,] -73.70720 9.028300
## [3,] -73.72440 9.034800
## [4,] -73.74170 9.037700
## [5,] -73.76420 9.045900
## [6,] -73.78610 9.055199
## [7,] -73.80400 9.056500
## [8,] -73.83280 9.047901
## [9,] -73.83690 9.058902
## [10,] -73.84380 9.067000
## [11,] -73.85300 9.080901
## [12,] -73.88650 9.110500
## [13,] -73.89800 9.137099
## [14,] -73.90030 9.148700
## [15,] -73.90440 9.163200
## [16,] -73.90840 9.179899
## [17,] -73.91760 9.185201
## [18,] -73.93840 9.188699
## [19,] -73.96200 9.187701
## [20,] -73.98340 9.192400
## [21,] -73.98570 9.193499
## [22,] -73.98450 9.206800
## [23,] -73.97240 9.223499
## [24,] -73.96960 9.234501
## [25,] -73.96440 9.257600
## [26,] -73.96840 9.275500
## [27,] -73.97480 9.288801
## [28,] -73.98460 9.317199
## [29,] -73.99840 9.333401
## [30,] -73.98110 9.339102
## [31,] -73.97540 9.352300
## [32,] -73.96790 9.374301
## [33,] -73.96730 9.386400
## [34,] -73.95240 9.408301
## [35,] -73.94660 9.421499
## [36,] -73.94780 9.429597
## [37,] -73.93450 9.446301
## [38,] -73.92240 9.454900
## [39,] -73.90510 9.458300
## [40,] -73.89470 9.453701
## [41,] -73.88840 9.450802
## [42,] -73.87690 9.450699
## [43,] -73.86070 9.456402
## [44,] -73.84750 9.465600
## [45,] -73.83940 9.477700
## [46,] -73.81520 9.496100
## [47,] -73.80720 9.510502
## [48,] -73.79160 9.496601
## [49,] -73.78580 9.480898
## [50,] -73.78060 9.470501
## [51,] -73.77080 9.453200
## [52,] -73.77020 9.434700
## [53,] -73.76790 9.423701
## [54,] -73.76210 9.412102
## [55,] -73.75920 9.399401
## [56,] -73.76100 9.391900
## [57,] -73.74140 9.390601
## [58,] -73.72640 9.389400
## [59,] -73.70970 9.379502
## [60,] -73.70160 9.370301
## [61,] -73.69640 9.358700
## [62,] -73.69120 9.329201
## [63,] -73.68770 9.306102
## [64,] -73.68830 9.284701
## [65,] -73.69520 9.261600
## [66,] -73.69750 9.250701
## [67,] -73.70090 9.240900
## [68,] -73.70090 9.229901
## [69,] -73.69750 9.218900
## [70,] -73.69280 9.203302
## [71,] -73.68940 9.194602
## [72,] -73.69110 9.183099
## [73,] -73.68530 9.176100
## [74,] -73.67610 9.167401
## [75,] -73.67440 9.158200
## [76,] -73.67380 9.144901
## [77,] -73.66340 9.136701
## [78,] -73.65300 9.111300
## [79,] -73.65650 9.084700
## [80,] -73.65360 9.073199
## [81,] -73.63400 9.067301
## [82,] -73.61490 9.072402
## [83,] -73.60400 9.074701
## [84,] -73.58960 9.067700
## [85,] -73.57920 9.057799
## [86,] -73.57230 9.058401
## [87,] -73.55840 9.067000
## [88,] -73.53650 9.071501
## [89,] -73.51750 9.061601
## [90,] -73.49680 9.061001
## [91,] -73.48240 9.079401
## [92,] -73.46970 9.093199
## [93,] -73.44090 9.097101
## [94,] -73.42714 9.106890
## [95,] -73.42650 9.100501
## [96,] -73.42650 9.086099
## [97,] -73.42870 9.065899
## [98,] -73.43280 9.046198
## [99,] -73.43740 9.030101
## [100,] -73.43790 9.005299
## [101,] -73.44140 8.992001
## [102,] -73.44600 8.981001
## [103,] -73.44940 8.970100
## [104,] -73.45170 8.963701
## [105,] -73.45170 8.952799
## [106,] -73.45230 8.940000
## [107,] -73.45170 8.933700
## [108,] -73.45060 8.928499
## [109,] -73.45060 8.926202
## [110,] -73.45810 8.929101
## [111,] -73.47540 8.935501
## [112,] -73.48750 8.940200
## [113,] -73.50710 8.959302
## [114,] -73.52670 8.974399
## [115,] -73.54340 8.986100
## [116,] -73.54980 9.010899
## [117,] -73.56420 9.022001
## [118,] -73.57920 9.037000
## [119,] -73.58670 9.031300
## [120,] -73.60340 9.022701
## [121,] -73.62820 9.015900
## [122,] -73.66970 9.019501
## [123,] -73.69730 9.019099
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.770370 9.219282
##
## Slot "ID":
## [1] "6"
##
## Slot "area":
## [1] 0.1214687
##
##
##
## Slot "plotOrder":
## [1] 2 6 4 1 5 3
##
## Slot "bbox":
## min max
## x -74.15633 -72.89888
## y 7.99750 10.25736
##
## Slot "proj4string":
## CRS arguments: +proj=longlat +datum=WGS84 +no_defs
Para visualizar el área de cada munipio es necesario instalar y llamar la librería “lwgeom”
library(lwgeom)
## Linking to liblwgeom 3.0.0beta1 r16016, GEOS 3.8.0, PROJ 6.3.1
Para calcular el área en metros cuadrados
Mun_Cesar$area <- st_geod_area(Mun_Cesar)
Para convertir lo anterior a kilómetros cuadrados
Mun_Cesar$km2 <- Mun_Cesar$area/(1000000)
Observar cómo quedó
Mun_Cesar$km2
## Units: [m^2]
## [1] 915.64403 1645.91395 572.30780 1397.17529 593.38209 1476.35547
## [7] 1151.51736 806.73777 996.39927 882.51184 391.02047 83.09969
## [13] 799.33577 744.84935 1464.53302 218.72098 447.83215 421.54990
## [19] 349.00526 908.24133 218.05999 784.71916 678.21668 4970.08120
Nuevamente es necesario convertir los datos a polígonos espaciales
Ces_mun <- as(Mun_Cesar, "Spatial")
head(Ces_mun)
## An object of class "SpatialPolygonsDataFrame"
## Slot "data":
## ID_0 ISO NAME_0 ID_1 NAME_1 ID_2 NAME_2 TYPE_2 ENGTYPE_2
## 1 53 COL Colombia 12 Cesar 445 Aguachica Municipio Municipality
## 2 53 COL Colombia 12 Cesar 446 Agustín Codazzi Municipio Municipality
## 3 53 COL Colombia 12 Cesar 447 Astrea Municipio Municipality
## 4 53 COL Colombia 12 Cesar 448 Becerril Municipio Municipality
## 5 53 COL Colombia 12 Cesar 449 Bosconia Municipio Municipality
## 6 53 COL Colombia 12 Cesar 450 Chimichagua Municipio Municipality
## NL_NAME_2 VARNAME_2 area km2
## 1 <NA> <NA> 915644033 [m^2] 915.6440 [m^2]
## 2 <NA> <NA> 1645913948 [m^2] 1645.9139 [m^2]
## 3 <NA> <NA> 572307799 [m^2] 572.3078 [m^2]
## 4 <NA> <NA> 1397175295 [m^2] 1397.1753 [m^2]
## 5 <NA> <NA> 593382094 [m^2] 593.3821 [m^2]
## 6 <NA> <NA> 1476355473 [m^2] 1476.3555 [m^2]
##
## Slot "polygons":
## [[1]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.624398 8.243963
##
## Slot "area":
## [1] 0.07514397
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.48020 8.307100
## [2,] -73.47730 8.290900
## [3,] -73.47840 8.266100
## [4,] -73.47840 8.249301
## [5,] -73.48010 8.233698
## [6,] -73.50200 8.218799
## [7,] -73.52400 8.227000
## [8,] -73.53840 8.231701
## [9,] -73.56080 8.223100
## [10,] -73.57410 8.208700
## [11,] -73.58790 8.193200
## [12,] -73.59080 8.171199
## [13,] -73.59890 8.161401
## [14,] -73.60000 8.152201
## [15,] -73.58960 8.130800
## [16,] -73.58270 8.118602
## [17,] -73.58670 8.106499
## [18,] -73.61550 8.096200
## [19,] -73.63690 8.092300
## [20,] -73.64380 8.089401
## [21,] -73.64840 8.077901
## [22,] -73.63680 8.046100
## [23,] -73.62880 8.022901
## [24,] -73.63620 8.023500
## [25,] -73.66330 8.022502
## [26,] -73.68180 8.008100
## [27,] -73.71920 8.005399
## [28,] -73.75560 7.997500
## [29,] -73.75900 8.005602
## [30,] -73.76590 8.013700
## [31,] -73.76940 8.027001
## [32,] -73.77170 8.032799
## [33,] -73.77580 8.043800
## [34,] -73.78610 8.055401
## [35,] -73.79590 8.066400
## [36,] -73.80060 8.071002
## [37,] -73.79600 8.083701
## [38,] -73.78850 8.107899
## [39,] -73.78850 8.116601
## [40,] -73.79600 8.113200
## [41,] -73.80014 8.115026
## [42,] -73.80760 8.118317
## [43,] -73.80920 8.126501
## [44,] -73.80060 8.130501
## [45,] -73.77230 8.124600
## [46,] -73.76140 8.135602
## [47,] -73.75510 8.143000
## [48,] -73.73890 8.163799
## [49,] -73.73610 8.175901
## [50,] -73.72110 8.178700
## [51,] -73.70380 8.178600
## [52,] -73.69280 8.183201
## [53,] -73.69230 8.188400
## [54,] -73.69980 8.205801
## [55,] -73.70670 8.223100
## [56,] -73.70840 8.235799
## [57,] -73.69810 8.255999
## [58,] -73.68940 8.269799
## [59,] -73.67910 8.281899
## [60,] -73.66930 8.298601
## [61,] -73.66010 8.325201
## [62,] -73.65080 8.343001
## [63,] -73.64910 8.362100
## [64,] -73.64910 8.370200
## [65,] -73.64280 8.374202
## [66,] -73.63360 8.375900
## [67,] -73.63590 8.386901
## [68,] -73.63700 8.396702
## [69,] -73.64110 8.415801
## [70,] -73.64220 8.430200
## [71,] -73.64510 8.442900
## [72,] -73.65030 8.463200
## [73,] -73.64340 8.464900
## [74,] -73.63070 8.465402
## [75,] -73.61290 8.467100
## [76,] -73.60130 8.468800
## [77,] -73.59150 8.473901
## [78,] -73.58460 8.484300
## [79,] -73.57940 8.493501
## [80,] -73.57140 8.496899
## [81,] -73.55083 8.506720
## [82,] -73.55060 8.502599
## [83,] -73.54080 8.499099
## [84,] -73.52870 8.494401
## [85,] -73.52640 8.478801
## [86,] -73.52240 8.470701
## [87,] -73.51080 8.468401
## [88,] -73.50850 8.469500
## [89,] -73.50050 8.475799
## [90,] -73.49640 8.479899
## [91,] -73.48890 8.471699
## [92,] -73.49470 8.460800
## [93,] -73.49640 8.450400
## [94,] -73.49640 8.440600
## [95,] -73.49350 8.430800
## [96,] -73.49410 8.421501
## [97,] -73.49470 8.417499
## [98,] -73.49750 8.412300
## [99,] -73.50100 8.402500
## [100,] -73.50560 8.396100
## [101,] -73.51080 8.388700
## [102,] -73.51420 8.380000
## [103,] -73.52350 8.370802
## [104,] -73.52120 8.361001
## [105,] -73.51190 8.352899
## [106,] -73.50330 8.346501
## [107,] -73.49350 8.338901
## [108,] -73.49170 8.328499
## [109,] -73.48710 8.315799
## [110,] -73.48020 8.307100
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.624398 8.243963
##
## Slot "ID":
## [1] "1"
##
## Slot "area":
## [1] 0.07514397
##
##
## [[2]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.261924 9.932845
##
## Slot "area":
## [1] 0.1356965
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -72.95625 10.013630
## [2,] -73.01650 9.960002
## [3,] -73.02800 9.952000
## [4,] -73.04650 9.943401
## [5,] -73.07930 9.923299
## [6,] -73.08860 9.920500
## [7,] -73.09830 9.917599
## [8,] -73.11050 9.912500
## [9,] -73.11850 9.905000
## [10,] -73.12080 9.888799
## [11,] -73.13060 9.869801
## [12,] -73.13920 9.861801
## [13,] -73.16000 9.850900
## [14,] -73.19000 9.842301
## [15,] -73.20960 9.836099
## [16,] -73.23150 9.831001
## [17,] -73.25620 9.825300
## [18,] -73.27930 9.820202
## [19,] -73.31330 9.808799
## [20,] -73.33580 9.802500
## [21,] -73.36750 9.796301
## [22,] -73.38940 9.788900
## [23,] -73.40550 9.783200
## [24,] -73.42680 9.776301
## [25,] -73.45340 9.768400
## [26,] -73.47350 9.756901
## [27,] -73.49140 9.749501
## [28,] -73.50810 9.743201
## [29,] -73.52310 9.726500
## [30,] -73.53170 9.711501
## [31,] -73.53580 9.699401
## [32,] -73.54040 9.686100
## [33,] -73.55190 9.677501
## [34,] -73.56050 9.661900
## [35,] -73.56280 9.645201
## [36,] -73.55300 9.641101
## [37,] -73.55650 9.638799
## [38,] -73.57490 9.638899
## [39,] -73.61120 9.639599
## [40,] -73.63780 9.640298
## [41,] -73.65850 9.648501
## [42,] -73.65790 9.666999
## [43,] -73.65560 9.683101
## [44,] -73.64410 9.703301
## [45,] -73.64760 9.725900
## [46,] -73.63490 9.735600
## [47,] -73.62970 9.744300
## [48,] -73.62230 9.752300
## [49,] -73.61020 9.762702
## [50,] -73.59630 9.775301
## [51,] -73.57390 9.800601
## [52,] -73.54100 9.830000
## [53,] -73.51340 9.852898
## [54,] -73.48170 9.869001
## [55,] -73.47070 9.894901
## [56,] -73.46900 9.920901
## [57,] -73.46960 9.945201
## [58,] -73.46730 9.953301
## [59,] -73.45870 9.964200
## [60,] -73.43270 9.973301
## [61,] -73.41140 9.985902
## [62,] -73.39930 10.003800
## [63,] -73.39070 10.022298
## [64,] -73.36420 10.030801
## [65,] -73.33250 10.036401
## [66,] -73.31000 10.035202
## [67,] -73.28920 10.031601
## [68,] -73.27140 10.031601
## [69,] -73.25290 10.031501
## [70,] -73.24020 10.032000
## [71,] -73.22240 10.034799
## [72,] -73.19760 10.039902
## [73,] -73.17970 10.046199
## [74,] -73.16760 10.062900
## [75,] -73.16070 10.069200
## [76,] -73.15260 10.070401
## [77,] -73.13760 10.072600
## [78,] -73.12500 10.074298
## [79,] -73.11290 10.082902
## [80,] -73.09790 10.096700
## [81,] -73.08000 10.109299
## [82,] -73.04430 10.139201
## [83,] -72.99990 10.171401
## [84,] -72.95960 10.207001
## [85,] -72.90305 10.257356
## [86,] -72.90227 10.252032
## [87,] -72.90438 10.233897
## [88,] -72.89888 10.212890
## [89,] -72.90147 10.209709
## [90,] -72.90754 10.207498
## [91,] -72.90889 10.194179
## [92,] -72.90939 10.175102
## [93,] -72.91611 10.158640
## [94,] -72.91845 10.141660
## [95,] -72.91698 10.130372
## [96,] -72.91404 10.108716
## [97,] -72.92067 10.099152
## [98,] -72.92710 10.086829
## [99,] -72.94760 10.063440
## [100,] -72.95364 10.046744
## [101,] -72.95061 10.030835
## [102,] -72.95233 10.023731
## [103,] -72.95625 10.013630
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.261924 9.932845
##
## Slot "ID":
## [1] "2"
##
## Slot "area":
## [1] 0.1356965
##
##
## [[3]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.978834 9.489856
##
## Slot "area":
## [1] 0.04712278
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.80720 9.510502
## [2,] -73.81520 9.496100
## [3,] -73.83940 9.477700
## [4,] -73.84750 9.465600
## [5,] -73.86070 9.456402
## [6,] -73.87690 9.450699
## [7,] -73.88840 9.450802
## [8,] -73.89470 9.453701
## [9,] -73.90510 9.458300
## [10,] -73.92240 9.454900
## [11,] -73.93450 9.446301
## [12,] -73.94780 9.429597
## [13,] -73.94660 9.421499
## [14,] -73.95240 9.408301
## [15,] -73.96730 9.386400
## [16,] -73.96790 9.374301
## [17,] -73.97540 9.352300
## [18,] -73.98110 9.339102
## [19,] -73.99840 9.333401
## [20,] -73.99960 9.344401
## [21,] -74.01060 9.353699
## [22,] -74.01800 9.358900
## [23,] -74.02840 9.368199
## [24,] -74.03420 9.372801
## [25,] -74.04110 9.378000
## [26,] -74.04630 9.387298
## [27,] -74.06250 9.405299
## [28,] -74.07520 9.418600
## [29,] -74.08610 9.431901
## [30,] -74.10170 9.444101
## [31,] -74.14840 9.466902
## [32,] -74.15633 9.477103
## [33,] -74.15470 9.483599
## [34,] -74.14780 9.487701
## [35,] -74.13690 9.495701
## [36,] -74.12770 9.500300
## [37,] -74.11960 9.507801
## [38,] -74.10810 9.522700
## [39,] -74.08620 9.545701
## [40,] -74.07580 9.561301
## [41,] -74.05330 9.582000
## [42,] -74.01700 9.582399
## [43,] -73.99400 9.575999
## [44,] -73.97380 9.575300
## [45,] -73.95820 9.575202
## [46,] -73.93570 9.576300
## [47,] -73.89420 9.580200
## [48,] -73.86080 9.580601
## [49,] -73.85040 9.574199
## [50,] -73.82280 9.572401
## [51,] -73.81010 9.546899
## [52,] -73.81060 9.534800
## [53,] -73.81000 9.520901
## [54,] -73.80720 9.510502
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.978834 9.489856
##
## Slot "ID":
## [1] "3"
##
## Slot "area":
## [1] 0.04712278
##
##
## [[4]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.217461 9.742881
##
## Slot "area":
## [1] 0.1151246
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -72.95625 10.013630
## [2,] -72.95907 10.006353
## [3,] -72.96041 10.000001
## [4,] -72.96081 9.998100
## [5,] -72.97114 9.988591
## [6,] -72.97757 9.976038
## [7,] -72.97917 9.960886
## [8,] -72.98707 9.943066
## [9,] -72.98959 9.928616
## [10,] -72.98951 9.917578
## [11,] -72.98638 9.909027
## [12,] -72.98558 9.899819
## [13,] -72.98058 9.892852
## [14,] -72.99045 9.882874
## [15,] -72.98360 9.875879
## [16,] -72.97874 9.875120
## [17,] -72.96613 9.865744
## [18,] -72.95698 9.857564
## [19,] -72.95032 9.853559
## [20,] -72.94694 9.847073
## [21,] -72.94772 9.840188
## [22,] -72.95883 9.824487
## [23,] -72.96332 9.818342
## [24,] -72.96895 9.813132
## [25,] -72.98583 9.798432
## [26,] -72.99506 9.784080
## [27,] -73.00190 9.758889
## [28,] -73.00627 9.744238
## [29,] -73.01943 9.730169
## [30,] -73.03722 9.699845
## [31,] -73.04992 9.684621
## [32,] -73.05591 9.669993
## [33,] -73.05829 9.654383
## [34,] -73.07920 9.650099
## [35,] -73.09070 9.643801
## [36,] -73.10110 9.637500
## [37,] -73.11610 9.628900
## [38,] -73.13510 9.617400
## [39,] -73.15520 9.610601
## [40,] -73.16620 9.610000
## [41,] -73.18180 9.605501
## [42,] -73.19560 9.600302
## [43,] -73.20830 9.603301
## [44,] -73.21580 9.603301
## [45,] -73.23250 9.595899
## [46,] -73.24690 9.585499
## [47,] -73.26880 9.580400
## [48,] -73.28780 9.582301
## [49,] -73.30160 9.582901
## [50,] -73.32410 9.580701
## [51,] -73.35240 9.587101
## [52,] -73.36680 9.588400
## [53,] -73.38120 9.594800
## [54,] -73.38810 9.606399
## [55,] -73.39620 9.621999
## [56,] -73.41410 9.634202
## [57,] -73.43200 9.641201
## [58,] -73.44520 9.648200
## [59,] -73.45440 9.659199
## [60,] -73.46370 9.674800
## [61,] -73.47640 9.674900
## [62,] -73.48500 9.672601
## [63,] -73.49080 9.670299
## [64,] -73.49830 9.667500
## [65,] -73.50460 9.665802
## [66,] -73.51320 9.659999
## [67,] -73.52190 9.658301
## [68,] -73.53170 9.645101
## [69,] -73.55300 9.641101
## [70,] -73.56280 9.645201
## [71,] -73.56050 9.661900
## [72,] -73.55190 9.677501
## [73,] -73.54040 9.686100
## [74,] -73.53580 9.699401
## [75,] -73.53170 9.711501
## [76,] -73.52310 9.726500
## [77,] -73.50810 9.743201
## [78,] -73.49140 9.749501
## [79,] -73.47350 9.756901
## [80,] -73.45340 9.768400
## [81,] -73.42680 9.776301
## [82,] -73.40550 9.783200
## [83,] -73.38940 9.788900
## [84,] -73.36750 9.796301
## [85,] -73.33580 9.802500
## [86,] -73.31330 9.808799
## [87,] -73.27930 9.820202
## [88,] -73.25620 9.825300
## [89,] -73.23150 9.831001
## [90,] -73.20960 9.836099
## [91,] -73.19000 9.842301
## [92,] -73.16000 9.850900
## [93,] -73.13920 9.861801
## [94,] -73.13060 9.869801
## [95,] -73.12080 9.888799
## [96,] -73.11850 9.905000
## [97,] -73.11050 9.912500
## [98,] -73.09830 9.917599
## [99,] -73.08860 9.920500
## [100,] -73.07930 9.923299
## [101,] -73.04650 9.943401
## [102,] -73.02800 9.952000
## [103,] -73.01650 9.960002
## [104,] -72.95625 10.013630
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.217461 9.742881
##
## Slot "ID":
## [1] "4"
##
## Slot "area":
## [1] 0.1151246
##
##
## [[5]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.888567 9.929217
##
## Slot "area":
## [1] 0.04892045
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.7618 9.846501
## [2,] -73.7768 9.844801
## [3,] -73.8016 9.828199
## [4,] -73.8160 9.814901
## [5,] -73.8287 9.804601
## [6,] -73.8413 9.797101
## [7,] -73.8742 9.781701
## [8,] -73.8765 9.784000
## [9,] -73.8799 9.789801
## [10,] -73.8817 9.791501
## [11,] -73.8857 9.796198
## [12,] -73.9117 9.811300
## [13,] -73.9255 9.823500
## [14,] -73.9365 9.842002
## [15,] -73.9515 9.864000
## [16,] -73.9596 9.885401
## [17,] -73.9867 9.911502
## [18,] -73.9999 9.916799
## [19,] -74.0230 9.931900
## [20,] -74.0316 9.949299
## [21,] -74.0316 9.957401
## [22,] -74.0518 9.973602
## [23,] -74.0645 9.985799
## [24,] -74.0167 10.004101
## [25,] -74.0155 10.015100
## [26,] -73.9936 10.023599
## [27,] -73.9666 10.036200
## [28,] -73.9470 10.037301
## [29,] -73.9245 10.040102
## [30,] -73.9008 10.043500
## [31,] -73.8772 10.046801
## [32,] -73.8507 10.059400
## [33,] -73.8513 10.054800
## [34,] -73.8530 10.049599
## [35,] -73.8547 10.036301
## [36,] -73.8518 10.030500
## [37,] -73.8368 10.029299
## [38,] -73.8190 10.026400
## [39,] -73.8080 10.019401
## [40,] -73.7976 10.002599
## [41,] -73.7942 9.983500
## [42,] -73.7803 9.949402
## [43,] -73.7595 9.898499
## [44,] -73.7520 9.883400
## [45,] -73.7486 9.867802
## [46,] -73.7532 9.848199
## [47,] -73.7618 9.846501
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.888567 9.929217
##
## Slot "ID":
## [1] "5"
##
## Slot "area":
## [1] 0.04892045
##
##
## [[6]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.770370 9.219282
##
## Slot "area":
## [1] 0.1214687
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.69730 9.019099
## [2,] -73.70720 9.028300
## [3,] -73.72440 9.034800
## [4,] -73.74170 9.037700
## [5,] -73.76420 9.045900
## [6,] -73.78610 9.055199
## [7,] -73.80400 9.056500
## [8,] -73.83280 9.047901
## [9,] -73.83690 9.058902
## [10,] -73.84380 9.067000
## [11,] -73.85300 9.080901
## [12,] -73.88650 9.110500
## [13,] -73.89800 9.137099
## [14,] -73.90030 9.148700
## [15,] -73.90440 9.163200
## [16,] -73.90840 9.179899
## [17,] -73.91760 9.185201
## [18,] -73.93840 9.188699
## [19,] -73.96200 9.187701
## [20,] -73.98340 9.192400
## [21,] -73.98570 9.193499
## [22,] -73.98450 9.206800
## [23,] -73.97240 9.223499
## [24,] -73.96960 9.234501
## [25,] -73.96440 9.257600
## [26,] -73.96840 9.275500
## [27,] -73.97480 9.288801
## [28,] -73.98460 9.317199
## [29,] -73.99840 9.333401
## [30,] -73.98110 9.339102
## [31,] -73.97540 9.352300
## [32,] -73.96790 9.374301
## [33,] -73.96730 9.386400
## [34,] -73.95240 9.408301
## [35,] -73.94660 9.421499
## [36,] -73.94780 9.429597
## [37,] -73.93450 9.446301
## [38,] -73.92240 9.454900
## [39,] -73.90510 9.458300
## [40,] -73.89470 9.453701
## [41,] -73.88840 9.450802
## [42,] -73.87690 9.450699
## [43,] -73.86070 9.456402
## [44,] -73.84750 9.465600
## [45,] -73.83940 9.477700
## [46,] -73.81520 9.496100
## [47,] -73.80720 9.510502
## [48,] -73.79160 9.496601
## [49,] -73.78580 9.480898
## [50,] -73.78060 9.470501
## [51,] -73.77080 9.453200
## [52,] -73.77020 9.434700
## [53,] -73.76790 9.423701
## [54,] -73.76210 9.412102
## [55,] -73.75920 9.399401
## [56,] -73.76100 9.391900
## [57,] -73.74140 9.390601
## [58,] -73.72640 9.389400
## [59,] -73.70970 9.379502
## [60,] -73.70160 9.370301
## [61,] -73.69640 9.358700
## [62,] -73.69120 9.329201
## [63,] -73.68770 9.306102
## [64,] -73.68830 9.284701
## [65,] -73.69520 9.261600
## [66,] -73.69750 9.250701
## [67,] -73.70090 9.240900
## [68,] -73.70090 9.229901
## [69,] -73.69750 9.218900
## [70,] -73.69280 9.203302
## [71,] -73.68940 9.194602
## [72,] -73.69110 9.183099
## [73,] -73.68530 9.176100
## [74,] -73.67610 9.167401
## [75,] -73.67440 9.158200
## [76,] -73.67380 9.144901
## [77,] -73.66340 9.136701
## [78,] -73.65300 9.111300
## [79,] -73.65650 9.084700
## [80,] -73.65360 9.073199
## [81,] -73.63400 9.067301
## [82,] -73.61490 9.072402
## [83,] -73.60400 9.074701
## [84,] -73.58960 9.067700
## [85,] -73.57920 9.057799
## [86,] -73.57230 9.058401
## [87,] -73.55840 9.067000
## [88,] -73.53650 9.071501
## [89,] -73.51750 9.061601
## [90,] -73.49680 9.061001
## [91,] -73.48240 9.079401
## [92,] -73.46970 9.093199
## [93,] -73.44090 9.097101
## [94,] -73.42714 9.106890
## [95,] -73.42650 9.100501
## [96,] -73.42650 9.086099
## [97,] -73.42870 9.065899
## [98,] -73.43280 9.046198
## [99,] -73.43740 9.030101
## [100,] -73.43790 9.005299
## [101,] -73.44140 8.992001
## [102,] -73.44600 8.981001
## [103,] -73.44940 8.970100
## [104,] -73.45170 8.963701
## [105,] -73.45170 8.952799
## [106,] -73.45230 8.940000
## [107,] -73.45170 8.933700
## [108,] -73.45060 8.928499
## [109,] -73.45060 8.926202
## [110,] -73.45810 8.929101
## [111,] -73.47540 8.935501
## [112,] -73.48750 8.940200
## [113,] -73.50710 8.959302
## [114,] -73.52670 8.974399
## [115,] -73.54340 8.986100
## [116,] -73.54980 9.010899
## [117,] -73.56420 9.022001
## [118,] -73.57920 9.037000
## [119,] -73.58670 9.031300
## [120,] -73.60340 9.022701
## [121,] -73.62820 9.015900
## [122,] -73.66970 9.019501
## [123,] -73.69730 9.019099
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.770370 9.219282
##
## Slot "ID":
## [1] "6"
##
## Slot "area":
## [1] 0.1214687
##
##
##
## Slot "plotOrder":
## [1] 2 6 4 1 5 3
##
## Slot "bbox":
## min max
## x -74.15633 -72.89888
## y 7.99750 10.25736
##
## Slot "proj4string":
## CRS arguments: +proj=longlat +datum=WGS84 +no_defs
Para graficar los datos
bins <- c(0, 50, 100, 200, 300, 500, 1000, 2000, Inf)
pal <-colorBin("PuRd", domain = Ces_mun$km2, bins=bins)
labels <- Mun_Cesar$NAME_2
labels
## [1] "Aguachica" "Agustín Codazzi" "Astrea"
## [4] "Becerril" "Bosconia" "Chimichagua"
## [7] "Chiriguaná" "Curumaní" "El Copey"
## [10] "El Paso" "Gamarra" "González"
## [13] "La Gloria" "La Jagua de Ibirico" "La Paz"
## [16] "Manaure" "Pailitas" "Pelaya"
## [19] "Río de Oro" "San Alberto" "San Diego"
## [22] "San Martín" "Tamalameque" "Valledupar"
library(leaflet)
m <- leaflet(Ces_mun) %>%
setView(-75.5, 7, 8) %>% addPolygons(
fillColor = ~pal(km2),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels) %>%
addLegend(pal = pal, values = ~km2, opacity = 0.7, title = NULL,
position = "bottomright")
m
Otra forma de realizar un mapa:
leaflet() %>%
addProviderTiles(providers$Esri.WorldImagery, options = providerTileOptions(opacity = 0.99)) %>%
addPolygons(data = Ces_mun, popup = Ces_mun$NAME_2,
stroke = TRUE, fillOpacity = 0.25, smoothFactor = 0.25
)
Es posible crear el mapa usando otros proveedores
leaflet() %>%
addProviderTiles(providers$Esri.WorldStreetMap, options = providerTileOptions(opacity = 0.99)) %>%
addPolygons(data = Ces_mun, popup = Ces_mun$NAME_2,
stroke = TRUE, fillOpacity = 0.25, smoothFactor = 0.25
)
leaflet() %>%
addProviderTiles(providers$Esri.NatGeoWorldMap, options = providerTileOptions(opacity = 0.99)) %>%
addPolygons(data = Ces_mun, popup = Ces_mun$NAME_2,
stroke = TRUE, fillOpacity = 0.25, smoothFactor = 0.25
)
leaflet() %>%
addProviderTiles(providers$Esri.WorldPhysical, options = providerTileOptions(opacity = 0.99)) %>%
addPolygons(data = Ces_mun, popup = Ces_mun$NAME_2,
stroke = TRUE, fillOpacity = 0.25, smoothFactor = 0.25
)