Este es un R Markdown Notebook. Mediante este sketch observaremos algunas funcionalidades geospaciales de R para lo cual usaremos algunas librerias como simple features (sf) y tidyverse.
Primero instalamos las librerias nescesarias, para ello usamos el siguiente comando:
#install.packages("tidyverse")
#install.packages("sf")
Luego, necesitamos cargar las dos bibliotecas:
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()
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
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)
## Simple feature collection with 6 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -77.149 ymin: -4.228429 xmax: -69.36835 ymax: 11.10792
## geographic CRS: WGS 84
## Warning: `...` is not empty.
##
## We detected these problematic arguments:
## * `needs_dots`
##
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 6 x 10
## ID_0 ISO NAME_0 ID_1 NAME_1 TYPE_1 ENGTYPE_1 NL_NAME_1 VARNAME_1
## <dbl> <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <chr>
## 1 53 COL Colom~ 1 Amazo~ Comis~ Commissi~ <NA> <NA>
## 2 53 COL Colom~ 2 Antio~ Depar~ Departme~ <NA> <NA>
## 3 53 COL Colom~ 3 Arauca Inten~ Intendan~ <NA> <NA>
## 4 53 COL Colom~ 4 Atlán~ Depar~ Departme~ <NA> <NA>
## 5 53 COL Colom~ 5 Bolív~ Depar~ Departme~ <NA> <NA>
## 6 53 COL Colom~ 6 Boyacá Depar~ Departme~ <NA> <NA>
## # ... with 1 more variable: geometry <MULTIPOLYGON [°]>
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]]
Para comprender los datas lo mejor es trazarlos, para ello es posible utilizar las funcionalidades de ggplot.
El primer paso es instalar la libreria:
#install.packages("ggplot2")
cargar la libreria instalada
library(ggplot2)
Ahora si utilizamos los datos del objeto deptos con las funciones de ggplot:
ggplot() + geom_sf(data = Deptos)
Sepuede utilizar cualquier sistema de referencias de coordenadas para trazar datos, en el caso de CRS 3978 es el sistema de referencia de coordenadas usado en canada
ggplot() + geom_sf(data = Deptos) + coord_sf(crs = st_crs(3978))
las propiedades del CRS con el código EPSG 32618. Corresponde a UTM 18 N. Por lo cual, en caso de requerir usar dicho CRS, es necesario convertir el objeto espacial de EPSG4326 a EPSG: 32618.Para ello realizamos lo siguiente
deptos_utm <- st_transform(Deptos, crs = st_crs(32618))
deptos_utm
## Simple feature collection with 32 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -245935.3 ymin: -469204.3 xmax: 1407491 ymax: 1763314
## projected CRS: WGS 84 / UTM zone 18N
## Warning: `...` is not empty.
##
## We detected these problematic arguments:
## * `needs_dots`
##
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 32 x 10
## ID_0 ISO NAME_0 ID_1 NAME_1 TYPE_1 ENGTYPE_1 NL_NAME_1 VARNAME_1
## * <dbl> <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <chr>
## 1 53 COL Colom~ 1 Amazo~ Comis~ Commissi~ <NA> <NA>
## 2 53 COL Colom~ 2 Antio~ Depar~ Departme~ <NA> <NA>
## 3 53 COL Colom~ 3 Arauca Inten~ Intendan~ <NA> <NA>
## 4 53 COL Colom~ 4 Atlán~ Depar~ Departme~ <NA> <NA>
## 5 53 COL Colom~ 5 Bolív~ Depar~ Departme~ <NA> <NA>
## 6 53 COL Colom~ 6 Boyacá Depar~ Departme~ <NA> <NA>
## 7 53 COL Colom~ 7 Córdo~ Depar~ Departme~ <NA> <NA>
## 8 53 COL Colom~ 8 Caldas Depar~ Departme~ <NA> <NA>
## 9 53 COL Colom~ 9 Caque~ Inten~ Intendan~ <NA> <NA>
## 10 53 COL Colom~ 10 Casan~ Inten~ Intendan~ <NA> <NA>
## # ... with 22 more rows, and 1 more variable: geometry <MULTIPOLYGON [m]>
ggplot() + geom_sf(data = deptos_utm)
4. Filtrar los datos geoespaciales basados en atributos como solo nos interesa el departamento de boyacá —
boyaca <- Deptos %>% filter(NAME_1 == "Boyacá")
trazamos el nuevo vector
ggplot() + geom_sf(data = boyaca)
Vamos a cargar los municipios colombianos y filtrar los del departamento de Boyacá
munic <- read_sf("C:/Users/JUAN PABLO/Documents/geo maps/COL_adm2.shp")
mun_boyaca <- munic %>% filter(NAME_1 == "Boyacá")
ggplot() + geom_sf(data = mun_boyaca)
mun_boyaca
## Simple feature collection with 123 features and 11 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -74.6743 ymin: 4.642001 xmax: -71.98309 ymax: 7.0275
## geographic CRS: WGS 84
## Warning: `...` is not empty.
##
## We detected these problematic arguments:
## * `needs_dots`
##
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 123 x 12
## ID_0 ISO NAME_0 ID_1 NAME_1 ID_2 NAME_2 TYPE_2 ENGTYPE_2 NL_NAME_2
## * <dbl> <chr> <chr> <dbl> <chr> <dbl> <chr> <chr> <chr> <chr>
## 1 53 COL Colom~ 6 Boyacá 199 Almei~ Munic~ Municipa~ <NA>
## 2 53 COL Colom~ 6 Boyacá 200 Aquit~ Munic~ Municipa~ <NA>
## 3 53 COL Colom~ 6 Boyacá 201 Arcab~ Munic~ Municipa~ <NA>
## 4 53 COL Colom~ 6 Boyacá 202 Belén <NA> <NA> <NA>
## 5 53 COL Colom~ 6 Boyacá 203 Berbeo Munic~ Municipa~ <NA>
## 6 53 COL Colom~ 6 Boyacá 204 Betei~ Munic~ Municipa~ <NA>
## 7 53 COL Colom~ 6 Boyacá 205 Boavi~ Munic~ Municipa~ <NA>
## 8 53 COL Colom~ 6 Boyacá 206 Boyacá Munic~ Municipa~ <NA>
## 9 53 COL Colom~ 6 Boyacá 207 Brice~ Munic~ Municipa~ <NA>
## 10 53 COL Colom~ 6 Boyacá 208 Buena~ Munic~ Municipa~ <NA>
## # ... with 113 more rows, and 2 more variables: VARNAME_2 <chr>,
## # geometry <MULTIPOLYGON [°]>
Vamos a asignar un centroide acada poligono que representan a los municipios de Caqueta para poder ponerles una etiqueta de ID a los municipios.
boyaca_points<- st_centroid(mun_boyaca)
## Warning in st_centroid.sf(mun_boyaca): 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
boyaca_points <- cbind(mun_boyaca,st_coordinates(st_centroid(mun_boyaca$geometry)))
## Warning in st_centroid.sfc(mun_boyaca$geometry): st_centroid does not give
## correct centroids for longitude/latitude data
ggplot(boyaca) +
geom_sf() +
geom_sf(data = boyaca_points, fill = "antiquewhite") +
geom_text(data = boyaca_points, aes(x=X, y=Y,label = ID_2), size = 2) +
coord_sf(xlim = c(-74.8, -71.8), ylim = c(4.4, 7.1), expand = FALSE)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
ggplot(boyaca) +
geom_sf(data=boyaca_points, aes(x=X, y=Y, fill =ID_2), color = "black", size = 0.25) + geom_text(data = boyaca_points, aes(x=X, y=Y,label = ID_2), size = 2) +
theme(aspect.ratio=1)+
scale_fill_distiller(name="ID_2", palette = "YlOrBr", breaks = pretty_breaks(n =4))+labs(title="Municipios del departamento de Boyacá")
## Warning: Ignoring unknown aesthetics: x, y
Podemos guadar nuestro proceso hasta el momento en PDF
ggsave("boyaca_municipios.pdf")
## Saving 7 x 5 in image
ggsave("map_boyaca.png", width = 6, height = 6, dpi = "screen")
library(leaflet)
Necesitamos convertir de caracteristicas simples a puntos espaciales
boy_ponits <- as(boyaca_points, "Spatial")
Despues observamos que hay dentro del objeto
head(boy_ponits)
## An object of class "SpatialPolygonsDataFrame"
## Slot "data":
## ID_0 ISO NAME_0 ID_1 NAME_1 ID_2 NAME_2 TYPE_2 ENGTYPE_2 NL_NAME_2
## 1 53 COL Colombia 6 Boyacá 199 Almeida Municipio Municipality <NA>
## 2 53 COL Colombia 6 Boyacá 200 Aquitania Municipio Municipality <NA>
## 3 53 COL Colombia 6 Boyacá 201 Arcabuco Municipio Municipality <NA>
## 4 53 COL Colombia 6 Boyacá 202 Belén <NA> <NA> <NA>
## 5 53 COL Colombia 6 Boyacá 203 Berbeo Municipio Municipality <NA>
## 6 53 COL Colombia 6 Boyacá 204 Beteitiva Municipio Municipality <NA>
## VARNAME_2 X Y
## 1 <NA> -73.41131 4.922605
## 2 <NA> -72.90192 5.403410
## 3 <NA> -73.46782 5.723896
## 4 <NA> -72.92481 5.976306
## 5 <NA> -73.12606 5.185135
## 6 <NA> -72.87078 5.894272
##
## Slot "polygons":
## [[1]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.411308 4.922605
##
## Slot "area":
## [1] 0.00391144
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.3883 4.900501
## [2,] -73.4033 4.888401
## [3,] -73.4206 4.876900
## [4,] -73.4315 4.878101
## [5,] -73.4436 4.874701
## [6,] -73.4598 4.871301
## [7,] -73.4488 4.875900
## [8,] -73.4465 4.882199
## [9,] -73.4436 4.893800
## [10,] -73.4385 4.910502
## [11,] -73.4339 4.922000
## [12,] -73.4241 4.931800
## [13,] -73.4252 4.941001
## [14,] -73.4120 4.961800
## [15,] -73.4114 4.971001
## [16,] -73.4097 4.981401
## [17,] -73.3953 4.980799
## [18,] -73.3935 4.969201
## [19,] -73.3860 4.957600
## [20,] -73.3780 4.933300
## [21,] -73.3883 4.920701
## [22,] -73.3970 4.905102
## [23,] -73.3883 4.900501
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.411308 4.922605
##
## Slot "ID":
## [1] "1"
##
## Slot "area":
## [1] 0.00391144
##
##
## [[2]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -72.90192 5.40341
##
## Slot "area":
## [1] 0.07373845
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.0553 5.276800
## [2,] -73.0571 5.282600
## [3,] -73.0582 5.289000
## [4,] -73.0582 5.297599
## [5,] -73.0513 5.308001
## [6,] -73.0484 5.315499
## [7,] -73.0536 5.327100
## [8,] -73.0629 5.333999
## [9,] -73.0600 5.339802
## [10,] -73.0490 5.349001
## [11,] -73.0392 5.351300
## [12,] -73.0387 5.360501
## [13,] -73.0387 5.366901
## [14,] -73.0323 5.371500
## [15,] -73.0254 5.381800
## [16,] -73.0237 5.393400
## [17,] -73.0226 5.403201
## [18,] -73.0128 5.415900
## [19,] -73.0076 5.429101
## [20,] -73.0030 5.442399
## [21,] -72.9868 5.460200
## [22,] -72.9782 5.474100
## [23,] -72.9701 5.486701
## [24,] -72.9580 5.498799
## [25,] -72.9511 5.508599
## [26,] -72.9448 5.517800
## [27,] -72.9425 5.517800
## [28,] -72.9356 5.530499
## [29,] -72.9287 5.536801
## [30,] -72.9252 5.543101
## [31,] -72.9166 5.561601
## [32,] -72.9125 5.572499
## [33,] -72.9097 5.575401
## [34,] -72.8872 5.571900
## [35,] -72.8768 5.571200
## [36,] -72.8716 5.570601
## [37,] -72.8630 5.566002
## [38,] -72.8543 5.560201
## [39,] -72.8428 5.557200
## [40,] -72.8365 5.563000
## [41,] -72.8278 5.586099
## [42,] -72.8151 5.605602
## [43,] -72.8082 5.624101
## [44,] -72.8013 5.613699
## [45,] -72.7909 5.606700
## [46,] -72.7811 5.596800
## [47,] -72.7725 5.583501
## [48,] -72.7656 5.577099
## [49,] -72.7598 5.574200
## [50,] -72.7604 5.564399
## [51,] -72.7609 5.552901
## [52,] -72.7603 5.539001
## [53,] -72.7540 5.523901
## [54,] -72.7494 5.504301
## [55,] -72.7471 5.491601
## [56,] -72.7378 5.480001
## [57,] -72.7321 5.472400
## [58,] -72.7222 5.447600
## [59,] -72.7159 5.434299
## [60,] -72.7061 5.425001
## [61,] -72.7101 5.422701
## [62,] -72.7107 5.415699
## [63,] -72.7176 5.404801
## [64,] -72.7291 5.404801
## [65,] -72.7418 5.415900
## [66,] -72.7516 5.426300
## [67,] -72.7591 5.429201
## [68,] -72.7695 5.427499
## [69,] -72.7804 5.413099
## [70,] -72.7977 5.405701
## [71,] -72.8098 5.397701
## [72,] -72.8202 5.384999
## [73,] -72.8208 5.373501
## [74,] -72.8196 5.363102
## [75,] -72.8208 5.358402
## [76,] -72.8317 5.341201
## [77,] -72.8507 5.328001
## [78,] -72.8605 5.321601
## [79,] -72.8703 5.311299
## [80,] -72.8824 5.289401
## [81,] -72.8974 5.279601
## [82,] -72.9129 5.259501
## [83,] -72.9320 5.242200
## [84,] -72.9515 5.226700
## [85,] -72.9613 5.221000
## [86,] -72.9717 5.210101
## [87,] -72.9648 5.205401
## [88,] -72.9625 5.199601
## [89,] -72.9590 5.195601
## [90,] -72.9590 5.188600
## [91,] -72.9584 5.181101
## [92,] -72.9671 5.180000
## [93,] -72.9734 5.179401
## [94,] -72.9832 5.176000
## [95,] -72.9890 5.176600
## [96,] -73.0051 5.176700
## [97,] -73.0109 5.180201
## [98,] -73.0270 5.183100
## [99,] -73.0328 5.184301
## [100,] -73.0317 5.202201
## [101,] -73.0271 5.224099
## [102,] -73.0305 5.235700
## [103,] -73.0438 5.244400
## [104,] -73.0490 5.252500
## [105,] -73.0542 5.265801
## [106,] -73.0553 5.276800
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -72.90192 5.40341
##
## Slot "ID":
## [1] "2"
##
## Slot "area":
## [1] 0.07373845
##
##
## [[3]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.467818 5.723896
##
## Slot "area":
## [1] 0.01332427
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.46480 5.675400
## [2,] -73.47290 5.682901
## [3,] -73.49020 5.688200
## [4,] -73.50750 5.691101
## [5,] -73.51790 5.692300
## [6,] -73.52420 5.694100
## [7,] -73.52420 5.697601
## [8,] -73.52890 5.704500
## [9,] -73.52310 5.726400
## [10,] -73.53060 5.731100
## [11,] -73.53920 5.732299
## [12,] -73.54160 5.745000
## [13,] -73.54040 5.750801
## [14,] -73.53810 5.759400
## [15,] -73.53120 5.761100
## [16,] -73.52250 5.766301
## [17,] -73.52020 5.775500
## [18,] -73.52200 5.784801
## [19,] -73.52720 5.793500
## [20,] -73.52890 5.802100
## [21,] -73.53060 5.818899
## [22,] -73.52600 5.821800
## [23,] -73.51160 5.814199
## [24,] -73.50350 5.799700
## [25,] -73.49490 5.790401
## [26,] -73.48620 5.789300
## [27,] -73.47640 5.797302
## [28,] -73.47010 5.792101
## [29,] -73.46320 5.790300
## [30,] -73.46150 5.789099
## [31,] -73.45630 5.778200
## [32,] -73.45340 5.770600
## [33,] -73.45220 5.768300
## [34,] -73.44990 5.762000
## [35,] -73.44760 5.755001
## [36,] -73.44700 5.751500
## [37,] -73.43840 5.745201
## [38,] -73.42970 5.740501
## [39,] -73.42110 5.724898
## [40,] -73.41300 5.713300
## [41,] -73.40380 5.704600
## [42,] -73.39630 5.692400
## [43,] -73.39450 5.684900
## [44,] -73.39110 5.678500
## [45,] -73.38820 5.674500
## [46,] -73.38470 5.669301
## [47,] -73.38470 5.660000
## [48,] -73.38990 5.649600
## [49,] -73.39050 5.643900
## [50,] -73.39293 5.630946
## [51,] -73.39560 5.631201
## [52,] -73.40550 5.635301
## [53,] -73.41350 5.646899
## [54,] -73.42390 5.652100
## [55,] -73.43310 5.658500
## [56,] -73.44180 5.662600
## [57,] -73.44470 5.671200
## [58,] -73.45620 5.675300
## [59,] -73.46480 5.675400
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.467818 5.723896
##
## Slot "ID":
## [1] "3"
##
## Slot "area":
## [1] 0.01332427
##
##
## [[4]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -72.924811 5.976306
##
## Slot "area":
## [1] 0.01263091
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -72.8194 5.951100
## [2,] -72.8205 5.947600
## [3,] -72.8355 5.947100
## [4,] -72.8459 5.941899
## [5,] -72.8609 5.934501
## [6,] -72.8718 5.930501
## [7,] -72.8868 5.928300
## [8,] -72.9030 5.926600
## [9,] -72.9127 5.924300
## [10,] -72.9202 5.923801
## [11,] -72.9295 5.919799
## [12,] -72.9387 5.920400
## [13,] -72.9427 5.922101
## [14,] -72.9508 5.925100
## [15,] -72.9508 5.932601
## [16,] -72.9554 5.938399
## [17,] -72.9693 5.945899
## [18,] -72.9773 5.946000
## [19,] -72.9796 5.949400
## [20,] -72.9854 5.956399
## [21,] -72.9894 5.961600
## [22,] -72.9917 5.963900
## [23,] -73.0027 5.987701
## [24,] -73.0016 5.992300
## [25,] -73.0004 5.996300
## [26,] -72.9975 6.000899
## [27,] -72.9935 6.010100
## [28,] -72.9877 6.016500
## [29,] -72.9843 6.024001
## [30,] -72.9797 6.032600
## [31,] -72.9751 6.037801
## [32,] -72.9722 6.040101
## [33,] -72.9664 6.045302
## [34,] -72.9601 6.045801
## [35,] -72.9543 6.052700
## [36,] -72.9474 6.058500
## [37,] -72.9365 6.044600
## [38,] -72.9318 6.032399
## [39,] -72.9272 6.024901
## [40,] -72.9186 6.013300
## [41,] -72.9076 6.003400
## [42,] -72.8995 5.994201
## [43,] -72.8920 5.984900
## [44,] -72.8828 5.977901
## [45,] -72.8626 5.977301
## [46,] -72.8534 5.976599
## [47,] -72.8465 5.976599
## [48,] -72.8407 5.976599
## [49,] -72.8332 5.978299
## [50,] -72.8321 5.975400
## [51,] -72.8246 5.971900
## [52,] -72.8165 5.965502
## [53,] -72.8125 5.956800
## [54,] -72.8165 5.953999
## [55,] -72.8194 5.951100
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -72.924811 5.976306
##
## Slot "ID":
## [1] "4"
##
## Slot "area":
## [1] 0.01263091
##
##
## [[5]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.126058 5.185135
##
## Slot "area":
## [1] 0.0051261
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.0639 5.140501
## [2,] -73.0795 5.133700
## [3,] -73.1221 5.124000
## [4,] -73.1239 5.130399
## [5,] -73.1285 5.133900
## [6,] -73.1406 5.153002
## [7,] -73.1440 5.157100
## [8,] -73.1527 5.173300
## [9,] -73.1596 5.180800
## [10,] -73.1648 5.186001
## [11,] -73.1735 5.197000
## [12,] -73.1740 5.203400
## [13,] -73.1637 5.208000
## [14,] -73.1521 5.216601
## [15,] -73.1441 5.221699
## [16,] -73.1331 5.232101
## [17,] -73.1222 5.242401
## [18,] -73.1026 5.258501
## [19,] -73.1003 5.260800
## [20,] -73.0980 5.256800
## [21,] -73.0980 5.251000
## [22,] -73.0997 5.245801
## [23,] -73.1014 5.236600
## [24,] -73.0985 5.231399
## [25,] -73.0985 5.225000
## [26,] -73.1089 5.219299
## [27,] -73.1187 5.213599
## [28,] -73.1227 5.208398
## [29,] -73.1204 5.200301
## [30,] -73.1164 5.195601
## [31,] -73.1164 5.189301
## [32,] -73.1164 5.177701
## [33,] -73.1095 5.165001
## [34,] -73.1043 5.152801
## [35,] -73.0945 5.147001
## [36,] -73.0858 5.144099
## [37,] -73.0737 5.144099
## [38,] -73.0639 5.140501
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.126058 5.185135
##
## Slot "ID":
## [1] "5"
##
## Slot "area":
## [1] 0.0051261
##
##
## [[6]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -72.870782 5.894272
##
## Slot "area":
## [1] 0.01047862
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -72.8499 5.849000
## [2,] -72.8585 5.847798
## [3,] -72.8660 5.846101
## [4,] -72.8758 5.845000
## [5,] -72.8793 5.840400
## [6,] -72.8833 5.833501
## [7,] -72.8856 5.832401
## [8,] -72.8902 5.832401
## [9,] -72.8971 5.832401
## [10,] -72.9023 5.830101
## [11,] -72.9046 5.827200
## [12,] -72.9098 5.825499
## [13,] -72.9133 5.853300
## [14,] -72.9202 5.863700
## [15,] -72.9254 5.874100
## [16,] -72.9335 5.882200
## [17,] -72.9410 5.889801
## [18,] -72.9462 5.894400
## [19,] -72.9554 5.900200
## [20,] -72.9439 5.905399
## [21,] -72.9404 5.908800
## [22,] -72.9364 5.908800
## [23,] -72.9295 5.919799
## [24,] -72.9202 5.923801
## [25,] -72.9127 5.924300
## [26,] -72.9030 5.926600
## [27,] -72.8868 5.928300
## [28,] -72.8718 5.930501
## [29,] -72.8609 5.934501
## [30,] -72.8459 5.941899
## [31,] -72.8355 5.947100
## [32,] -72.8205 5.947600
## [33,] -72.8194 5.951100
## [34,] -72.8125 5.949899
## [35,] -72.8078 5.948101
## [36,] -72.7998 5.947000
## [37,] -72.7969 5.944600
## [38,] -72.7957 5.938900
## [39,] -72.7963 5.934800
## [40,] -72.8009 5.923299
## [41,] -72.8032 5.917501
## [42,] -72.8101 5.903701
## [43,] -72.8130 5.894999
## [44,] -72.8176 5.888100
## [45,] -72.8274 5.874300
## [46,] -72.8384 5.862200
## [47,] -72.8453 5.855301
## [48,] -72.8499 5.849000
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -72.870782 5.894272
##
## Slot "ID":
## [1] "6"
##
## Slot "area":
## [1] 0.01047862
##
##
##
## Slot "plotOrder":
## [1] 2 3 4 6 5 1
##
## Slot "bbox":
## min max
## x -73.541603 -72.7061
## y 4.871301 6.0585
##
## Slot "proj4string":
## CRS arguments: +proj=longlat +datum=WGS84 +no_defs
Para obetner el areas de los municipios instalamos y llamamos las siguientes librerias
library(lwgeom)
## Linking to liblwgeom 3.0.0beta1 r16016, GEOS 3.8.0, PROJ 6.3.1
mun_boyaca$area <- st_area(mun_boyaca)
Creamos un campo paraalmacenar el area en kilometros cuadrados y verificamos la salida
mun_boyaca$km2 <- mun_boyaca$area/(100000)
mun_boyaca$km2
## Units: [m^2]
## [1] 479.7334 9037.2455 1632.1342 1546.5223 628.4607 1283.1822
## [7] 1785.9268 580.5340 540.3198 878.5452 158.5462 1870.7899
## [13] 885.6730 3107.9600 546.4079 388.3464 1514.1470 1298.9509
## [19] 7313.2186 5628.0458 1350.6323 609.0598 1081.5644 522.8278
## [25] 1749.5417 635.9134 973.1592 463.3178 13135.6649 332.2368
## [31] 2811.2784 1808.5505 796.0334 910.0209 986.7122 1280.2692
## [37] 894.9661 2017.2954 684.0413 378.9154 722.8849 8799.5611
## [43] 447.6551 459.6802 1329.7290 621.6379 1986.1630 460.2968
## [49] 6335.8878 1874.0220 1622.5746 2459.3149 3609.3416 568.5137
## [55] 2128.1716 651.8185 1708.7576 512.6003 398.5799 543.0010
## [61] 5109.6286 3542.2549 625.5822 4162.6337 2722.1976 393.2367
## [67] 2792.0117 5706.2090 1111.6939 2923.4229 3330.1586 14391.8169
## [73] 955.2294 2077.4829 1398.7297 1868.9415 655.2678 2838.5552
## [79] 1651.9258 1040.0139 1002.5682 2627.1646 1178.1661 1049.6359
## [85] 1830.4830 4924.4555 746.9779 745.8023 723.4770 1416.1040
## [91] 561.1386 1485.6929 1409.9821 1802.7338 6365.0190 2072.0233
## [97] 788.2340 471.5936 303.5042 2817.5359 2135.0974 1056.1560
## [103] 331.3001 2075.1419 377.8645 1126.2569 1157.9385 729.6197
## [109] 710.0005 1564.3187 806.1687 340.4449 1824.9107 2212.0266
## [115] 279.5687 917.1484 1498.8357 1525.7119 1532.4558 1839.1159
## [121] 1129.0525 598.8663 2605.4623
boy_mun <- as(mun_boyaca, 'Spatial')
head(boy_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 NL_NAME_2
## 1 53 COL Colombia 6 Boyacá 199 Almeida Municipio Municipality <NA>
## 2 53 COL Colombia 6 Boyacá 200 Aquitania Municipio Municipality <NA>
## 3 53 COL Colombia 6 Boyacá 201 Arcabuco Municipio Municipality <NA>
## 4 53 COL Colombia 6 Boyacá 202 Belén <NA> <NA> <NA>
## 5 53 COL Colombia 6 Boyacá 203 Berbeo Municipio Municipality <NA>
## 6 53 COL Colombia 6 Boyacá 204 Beteitiva Municipio Municipality <NA>
## VARNAME_2 area km2
## 1 <NA> 47973340 [m^2] 479.7334 [m^2]
## 2 <NA> 903724548 [m^2] 9037.2455 [m^2]
## 3 <NA> 163213422 [m^2] 1632.1342 [m^2]
## 4 <NA> 154652234 [m^2] 1546.5223 [m^2]
## 5 <NA> 62846073 [m^2] 628.4607 [m^2]
## 6 <NA> 128318216 [m^2] 1283.1822 [m^2]
##
## Slot "polygons":
## [[1]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.411308 4.922605
##
## Slot "area":
## [1] 0.00391144
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.3883 4.900501
## [2,] -73.4033 4.888401
## [3,] -73.4206 4.876900
## [4,] -73.4315 4.878101
## [5,] -73.4436 4.874701
## [6,] -73.4598 4.871301
## [7,] -73.4488 4.875900
## [8,] -73.4465 4.882199
## [9,] -73.4436 4.893800
## [10,] -73.4385 4.910502
## [11,] -73.4339 4.922000
## [12,] -73.4241 4.931800
## [13,] -73.4252 4.941001
## [14,] -73.4120 4.961800
## [15,] -73.4114 4.971001
## [16,] -73.4097 4.981401
## [17,] -73.3953 4.980799
## [18,] -73.3935 4.969201
## [19,] -73.3860 4.957600
## [20,] -73.3780 4.933300
## [21,] -73.3883 4.920701
## [22,] -73.3970 4.905102
## [23,] -73.3883 4.900501
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.411308 4.922605
##
## Slot "ID":
## [1] "1"
##
## Slot "area":
## [1] 0.00391144
##
##
## [[2]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -72.90192 5.40341
##
## Slot "area":
## [1] 0.07373845
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.0553 5.276800
## [2,] -73.0571 5.282600
## [3,] -73.0582 5.289000
## [4,] -73.0582 5.297599
## [5,] -73.0513 5.308001
## [6,] -73.0484 5.315499
## [7,] -73.0536 5.327100
## [8,] -73.0629 5.333999
## [9,] -73.0600 5.339802
## [10,] -73.0490 5.349001
## [11,] -73.0392 5.351300
## [12,] -73.0387 5.360501
## [13,] -73.0387 5.366901
## [14,] -73.0323 5.371500
## [15,] -73.0254 5.381800
## [16,] -73.0237 5.393400
## [17,] -73.0226 5.403201
## [18,] -73.0128 5.415900
## [19,] -73.0076 5.429101
## [20,] -73.0030 5.442399
## [21,] -72.9868 5.460200
## [22,] -72.9782 5.474100
## [23,] -72.9701 5.486701
## [24,] -72.9580 5.498799
## [25,] -72.9511 5.508599
## [26,] -72.9448 5.517800
## [27,] -72.9425 5.517800
## [28,] -72.9356 5.530499
## [29,] -72.9287 5.536801
## [30,] -72.9252 5.543101
## [31,] -72.9166 5.561601
## [32,] -72.9125 5.572499
## [33,] -72.9097 5.575401
## [34,] -72.8872 5.571900
## [35,] -72.8768 5.571200
## [36,] -72.8716 5.570601
## [37,] -72.8630 5.566002
## [38,] -72.8543 5.560201
## [39,] -72.8428 5.557200
## [40,] -72.8365 5.563000
## [41,] -72.8278 5.586099
## [42,] -72.8151 5.605602
## [43,] -72.8082 5.624101
## [44,] -72.8013 5.613699
## [45,] -72.7909 5.606700
## [46,] -72.7811 5.596800
## [47,] -72.7725 5.583501
## [48,] -72.7656 5.577099
## [49,] -72.7598 5.574200
## [50,] -72.7604 5.564399
## [51,] -72.7609 5.552901
## [52,] -72.7603 5.539001
## [53,] -72.7540 5.523901
## [54,] -72.7494 5.504301
## [55,] -72.7471 5.491601
## [56,] -72.7378 5.480001
## [57,] -72.7321 5.472400
## [58,] -72.7222 5.447600
## [59,] -72.7159 5.434299
## [60,] -72.7061 5.425001
## [61,] -72.7101 5.422701
## [62,] -72.7107 5.415699
## [63,] -72.7176 5.404801
## [64,] -72.7291 5.404801
## [65,] -72.7418 5.415900
## [66,] -72.7516 5.426300
## [67,] -72.7591 5.429201
## [68,] -72.7695 5.427499
## [69,] -72.7804 5.413099
## [70,] -72.7977 5.405701
## [71,] -72.8098 5.397701
## [72,] -72.8202 5.384999
## [73,] -72.8208 5.373501
## [74,] -72.8196 5.363102
## [75,] -72.8208 5.358402
## [76,] -72.8317 5.341201
## [77,] -72.8507 5.328001
## [78,] -72.8605 5.321601
## [79,] -72.8703 5.311299
## [80,] -72.8824 5.289401
## [81,] -72.8974 5.279601
## [82,] -72.9129 5.259501
## [83,] -72.9320 5.242200
## [84,] -72.9515 5.226700
## [85,] -72.9613 5.221000
## [86,] -72.9717 5.210101
## [87,] -72.9648 5.205401
## [88,] -72.9625 5.199601
## [89,] -72.9590 5.195601
## [90,] -72.9590 5.188600
## [91,] -72.9584 5.181101
## [92,] -72.9671 5.180000
## [93,] -72.9734 5.179401
## [94,] -72.9832 5.176000
## [95,] -72.9890 5.176600
## [96,] -73.0051 5.176700
## [97,] -73.0109 5.180201
## [98,] -73.0270 5.183100
## [99,] -73.0328 5.184301
## [100,] -73.0317 5.202201
## [101,] -73.0271 5.224099
## [102,] -73.0305 5.235700
## [103,] -73.0438 5.244400
## [104,] -73.0490 5.252500
## [105,] -73.0542 5.265801
## [106,] -73.0553 5.276800
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -72.90192 5.40341
##
## Slot "ID":
## [1] "2"
##
## Slot "area":
## [1] 0.07373845
##
##
## [[3]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.467818 5.723896
##
## Slot "area":
## [1] 0.01332427
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.46480 5.675400
## [2,] -73.47290 5.682901
## [3,] -73.49020 5.688200
## [4,] -73.50750 5.691101
## [5,] -73.51790 5.692300
## [6,] -73.52420 5.694100
## [7,] -73.52420 5.697601
## [8,] -73.52890 5.704500
## [9,] -73.52310 5.726400
## [10,] -73.53060 5.731100
## [11,] -73.53920 5.732299
## [12,] -73.54160 5.745000
## [13,] -73.54040 5.750801
## [14,] -73.53810 5.759400
## [15,] -73.53120 5.761100
## [16,] -73.52250 5.766301
## [17,] -73.52020 5.775500
## [18,] -73.52200 5.784801
## [19,] -73.52720 5.793500
## [20,] -73.52890 5.802100
## [21,] -73.53060 5.818899
## [22,] -73.52600 5.821800
## [23,] -73.51160 5.814199
## [24,] -73.50350 5.799700
## [25,] -73.49490 5.790401
## [26,] -73.48620 5.789300
## [27,] -73.47640 5.797302
## [28,] -73.47010 5.792101
## [29,] -73.46320 5.790300
## [30,] -73.46150 5.789099
## [31,] -73.45630 5.778200
## [32,] -73.45340 5.770600
## [33,] -73.45220 5.768300
## [34,] -73.44990 5.762000
## [35,] -73.44760 5.755001
## [36,] -73.44700 5.751500
## [37,] -73.43840 5.745201
## [38,] -73.42970 5.740501
## [39,] -73.42110 5.724898
## [40,] -73.41300 5.713300
## [41,] -73.40380 5.704600
## [42,] -73.39630 5.692400
## [43,] -73.39450 5.684900
## [44,] -73.39110 5.678500
## [45,] -73.38820 5.674500
## [46,] -73.38470 5.669301
## [47,] -73.38470 5.660000
## [48,] -73.38990 5.649600
## [49,] -73.39050 5.643900
## [50,] -73.39293 5.630946
## [51,] -73.39560 5.631201
## [52,] -73.40550 5.635301
## [53,] -73.41350 5.646899
## [54,] -73.42390 5.652100
## [55,] -73.43310 5.658500
## [56,] -73.44180 5.662600
## [57,] -73.44470 5.671200
## [58,] -73.45620 5.675300
## [59,] -73.46480 5.675400
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.467818 5.723896
##
## Slot "ID":
## [1] "3"
##
## Slot "area":
## [1] 0.01332427
##
##
## [[4]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -72.924811 5.976306
##
## Slot "area":
## [1] 0.01263091
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -72.8194 5.951100
## [2,] -72.8205 5.947600
## [3,] -72.8355 5.947100
## [4,] -72.8459 5.941899
## [5,] -72.8609 5.934501
## [6,] -72.8718 5.930501
## [7,] -72.8868 5.928300
## [8,] -72.9030 5.926600
## [9,] -72.9127 5.924300
## [10,] -72.9202 5.923801
## [11,] -72.9295 5.919799
## [12,] -72.9387 5.920400
## [13,] -72.9427 5.922101
## [14,] -72.9508 5.925100
## [15,] -72.9508 5.932601
## [16,] -72.9554 5.938399
## [17,] -72.9693 5.945899
## [18,] -72.9773 5.946000
## [19,] -72.9796 5.949400
## [20,] -72.9854 5.956399
## [21,] -72.9894 5.961600
## [22,] -72.9917 5.963900
## [23,] -73.0027 5.987701
## [24,] -73.0016 5.992300
## [25,] -73.0004 5.996300
## [26,] -72.9975 6.000899
## [27,] -72.9935 6.010100
## [28,] -72.9877 6.016500
## [29,] -72.9843 6.024001
## [30,] -72.9797 6.032600
## [31,] -72.9751 6.037801
## [32,] -72.9722 6.040101
## [33,] -72.9664 6.045302
## [34,] -72.9601 6.045801
## [35,] -72.9543 6.052700
## [36,] -72.9474 6.058500
## [37,] -72.9365 6.044600
## [38,] -72.9318 6.032399
## [39,] -72.9272 6.024901
## [40,] -72.9186 6.013300
## [41,] -72.9076 6.003400
## [42,] -72.8995 5.994201
## [43,] -72.8920 5.984900
## [44,] -72.8828 5.977901
## [45,] -72.8626 5.977301
## [46,] -72.8534 5.976599
## [47,] -72.8465 5.976599
## [48,] -72.8407 5.976599
## [49,] -72.8332 5.978299
## [50,] -72.8321 5.975400
## [51,] -72.8246 5.971900
## [52,] -72.8165 5.965502
## [53,] -72.8125 5.956800
## [54,] -72.8165 5.953999
## [55,] -72.8194 5.951100
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -72.924811 5.976306
##
## Slot "ID":
## [1] "4"
##
## Slot "area":
## [1] 0.01263091
##
##
## [[5]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -73.126058 5.185135
##
## Slot "area":
## [1] 0.0051261
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -73.0639 5.140501
## [2,] -73.0795 5.133700
## [3,] -73.1221 5.124000
## [4,] -73.1239 5.130399
## [5,] -73.1285 5.133900
## [6,] -73.1406 5.153002
## [7,] -73.1440 5.157100
## [8,] -73.1527 5.173300
## [9,] -73.1596 5.180800
## [10,] -73.1648 5.186001
## [11,] -73.1735 5.197000
## [12,] -73.1740 5.203400
## [13,] -73.1637 5.208000
## [14,] -73.1521 5.216601
## [15,] -73.1441 5.221699
## [16,] -73.1331 5.232101
## [17,] -73.1222 5.242401
## [18,] -73.1026 5.258501
## [19,] -73.1003 5.260800
## [20,] -73.0980 5.256800
## [21,] -73.0980 5.251000
## [22,] -73.0997 5.245801
## [23,] -73.1014 5.236600
## [24,] -73.0985 5.231399
## [25,] -73.0985 5.225000
## [26,] -73.1089 5.219299
## [27,] -73.1187 5.213599
## [28,] -73.1227 5.208398
## [29,] -73.1204 5.200301
## [30,] -73.1164 5.195601
## [31,] -73.1164 5.189301
## [32,] -73.1164 5.177701
## [33,] -73.1095 5.165001
## [34,] -73.1043 5.152801
## [35,] -73.0945 5.147001
## [36,] -73.0858 5.144099
## [37,] -73.0737 5.144099
## [38,] -73.0639 5.140501
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -73.126058 5.185135
##
## Slot "ID":
## [1] "5"
##
## Slot "area":
## [1] 0.0051261
##
##
## [[6]]
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] -72.870782 5.894272
##
## Slot "area":
## [1] 0.01047862
##
## Slot "hole":
## [1] FALSE
##
## Slot "ringDir":
## [1] 1
##
## Slot "coords":
## [,1] [,2]
## [1,] -72.8499 5.849000
## [2,] -72.8585 5.847798
## [3,] -72.8660 5.846101
## [4,] -72.8758 5.845000
## [5,] -72.8793 5.840400
## [6,] -72.8833 5.833501
## [7,] -72.8856 5.832401
## [8,] -72.8902 5.832401
## [9,] -72.8971 5.832401
## [10,] -72.9023 5.830101
## [11,] -72.9046 5.827200
## [12,] -72.9098 5.825499
## [13,] -72.9133 5.853300
## [14,] -72.9202 5.863700
## [15,] -72.9254 5.874100
## [16,] -72.9335 5.882200
## [17,] -72.9410 5.889801
## [18,] -72.9462 5.894400
## [19,] -72.9554 5.900200
## [20,] -72.9439 5.905399
## [21,] -72.9404 5.908800
## [22,] -72.9364 5.908800
## [23,] -72.9295 5.919799
## [24,] -72.9202 5.923801
## [25,] -72.9127 5.924300
## [26,] -72.9030 5.926600
## [27,] -72.8868 5.928300
## [28,] -72.8718 5.930501
## [29,] -72.8609 5.934501
## [30,] -72.8459 5.941899
## [31,] -72.8355 5.947100
## [32,] -72.8205 5.947600
## [33,] -72.8194 5.951100
## [34,] -72.8125 5.949899
## [35,] -72.8078 5.948101
## [36,] -72.7998 5.947000
## [37,] -72.7969 5.944600
## [38,] -72.7957 5.938900
## [39,] -72.7963 5.934800
## [40,] -72.8009 5.923299
## [41,] -72.8032 5.917501
## [42,] -72.8101 5.903701
## [43,] -72.8130 5.894999
## [44,] -72.8176 5.888100
## [45,] -72.8274 5.874300
## [46,] -72.8384 5.862200
## [47,] -72.8453 5.855301
## [48,] -72.8499 5.849000
##
##
##
## Slot "plotOrder":
## [1] 1
##
## Slot "labpt":
## [1] -72.870782 5.894272
##
## Slot "ID":
## [1] "6"
##
## Slot "area":
## [1] 0.01047862
##
##
##
## Slot "plotOrder":
## [1] 2 3 4 6 5 1
##
## Slot "bbox":
## min max
## x -73.541603 -72.7061
## y 4.871301 6.0585
##
## Slot "proj4string":
## CRS arguments: +proj=longlat +datum=WGS84 +no_defs
ahora preparemos el plot
bins <- c(0, 50, 100, 200, 300, 500, 1000, 2000, Inf)
pal <- colorBin("OrRd", domain = boy_mun$km2, bins = bins)
labels <- mun_boyaca$NAME_2
labels
## [1] "Almeida" "Aquitania" "Arcabuco"
## [4] "Belén" "Berbeo" "Beteitiva"
## [7] "Boavita" "Boyacá" "Briceño"
## [10] "Buenavista" "Busbanza" "Cómbita"
## [13] "Caldas" "Campohermoso" "Cerinza"
## [16] "Chíquiza" "Chinavita" "Chiquinquirá"
## [19] "Chiscas" "Chita" "Chitaraque"
## [22] "Chivatá" "Chivor" "Ciénaga"
## [25] "Coper" "Corrales" "Covarachía"
## [28] "Cuítiva" "Cubará" "Cucaita"
## [31] "Duitama" "El Cocuy" "El Espino"
## [34] "Firavitoba" "Floresta" "Gámeza"
## [37] "Gachantivá" "Garagoa" "Guacamayas"
## [40] "Guateque" "Guayatá" "Guicán"
## [43] "Izá" "Jenesano" "Jericó"
## [46] "La Capilla" "La Uvita" "La Victoria"
## [49] "Labranzagrande" "Macanal" "Maripí"
## [52] "Miraflores" "Mongua" "Monguí"
## [55] "Moniquirá" "Motavita" "Muzo"
## [58] "Nobsa" "Nuevo Colón" "Oicatá"
## [61] "Otanche" "Páez" "Pachavita"
## [64] "Paipa" "Pajarito" "Panqueba"
## [67] "Pauna" "Paya" "Paz de Río"
## [70] "Pesca" "Pisba" "Puerto Boyacá"
## [73] "Quípama" "Ráquira" "Ramiriquí"
## [76] "Rondón" "Sáchica" "Saboyá"
## [79] "Samacá" "San Eduardo" "San José de Pare"
## [82] "San Luis de Gaceno" "San Mateo" "San Miguel de Sema"
## [85] "San Pablo de Borbur" "Santa María" "Santa Rosa de Viterbo"
## [88] "Santa Sofía" "Santana" "Sativanorte"
## [91] "Sativasur" "Siachoque" "Soatá"
## [94] "Socha" "Socotá" "Sogamoso"
## [97] "Somondoco" "Soracá" "Sora"
## [100] "Sotaquirá" "Susacón" "Sutamarchán"
## [103] "Sutatenza" "Tasco" "Tenza"
## [106] "Tibaná" "Tibasosa" "Tinjacá"
## [109] "Tipacoque" "Toca" "Toguí"
## [112] "Topagá" "Tota" "Tunja"
## [115] "Tunungua" "Turmequé" "Tuta"
## [118] "Tutazá" "Umbita" "Ventaquemada"
## [121] "Villa de Leyva" "Viracachá" "Zetaquirá"
Ha llegado el momento de crear el plot
m <- leaflet(boy_mun) %>%
addProviderTiles(providers$CartoDB.PositronNoLabels) %>%
setView(-77, 2, 7.4) %>% addPolygons(
fillColor = ~pal(km2),
weight = 2,
opacity = 1,
color = "black",
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
NA
## [1] NA
Puede probar diferentes proveedores para mejorar su mapa. Aproveche la función de completar con pestañas para seleccionar el mapa base preferido simplemente desplazándose por la lista de proveedores con addProviderTiles()
cap_boyaca <- munic %>% filter(NAME_2 == "Tuta")
cap_boyaca$area <- st_area(cap_boyaca)
cap_boyaca$km2 <-cap_boyaca$area/(1000000)
cap_boyaca$km2
## 149.8836 [m^2]
Podemos visualizar el departamento de caqueta en el mundo
boy_cap <- as(cap_boyaca, 'Spatial')
leaflet(boy_mun) %>%
addProviderTiles(providers$Esri.WorldImagery, options = providerTileOptions(opacity = 0.99)) %>%
addPolygons(data = boy_mun, popup = boy_mun$NAME_2,
stroke = TRUE, fillOpacity = 0.25, smoothFactor = 0.25)
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_Colombia.1252 LC_CTYPE=Spanish_Colombia.1252
## [3] LC_MONETARY=Spanish_Colombia.1252 LC_NUMERIC=C
## [5] LC_TIME=Spanish_Colombia.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] lwgeom_0.2-5 leaflet_2.0.3 scales_1.1.1 sf_0.9-6
## [5] forcats_0.5.0 stringr_1.4.0 dplyr_1.0.0 purrr_0.3.4
## [9] readr_1.3.1 tidyr_1.1.0 tibble_3.0.2 ggplot2_3.3.2
## [13] tidyverse_1.3.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.5 lattice_0.20-41 lubridate_1.7.9
## [4] leaflet.providers_1.9.0 class_7.3-17 assertthat_0.2.1
## [7] digest_0.6.25 utf8_1.1.4 R6_2.4.1
## [10] cellranger_1.1.0 backports_1.1.7 reprex_0.3.0
## [13] evaluate_0.14 e1071_1.7-3 httr_1.4.1
## [16] pillar_1.4.6 rlang_0.4.6 readxl_1.3.1
## [19] rstudioapi_0.11 blob_1.2.1 rmarkdown_2.3
## [22] htmlwidgets_1.5.1 munsell_0.5.0 broom_0.7.0
## [25] compiler_4.0.2 modelr_0.1.8 xfun_0.15
## [28] pkgconfig_2.0.3 htmltools_0.5.0 tidyselect_1.1.0
## [31] fansi_0.4.1 crayon_1.3.4 dbplyr_1.4.4
## [34] withr_2.2.0 grid_4.0.2 jsonlite_1.7.0
## [37] gtable_0.3.0 lifecycle_0.2.0 DBI_1.1.0
## [40] magrittr_1.5 units_0.6-7 KernSmooth_2.23-17
## [43] cli_2.0.2 stringi_1.4.6 farver_2.0.3
## [46] fs_1.4.2 sp_1.4-2 xml2_1.3.2
## [49] ellipsis_0.3.1 generics_0.0.2 vctrs_0.3.1
## [52] RColorBrewer_1.1-2 tools_4.0.2 glue_1.4.1
## [55] hms_0.5.3 crosstalk_1.1.0.1 yaml_2.2.1
## [58] colorspace_1.4-1 classInt_0.4-3 rvest_0.3.5
## [61] knitr_1.29 haven_2.3.1