Lo que hacemos primero es cargar las librerias que vamos a ocupar.
library(tidycensus)
library(tmap)
library(tmaptools)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
Ahora importamos los datos desde un archivo .shp
shp <- st_read("C:/shapes/CENSO_Corrientes_con_datos/Corrientes_con_datos.shp",
stringsAsFactors = FALSE)
## Reading layer `Corrientes_con_datos' from data source `C:\shapes\CENSO_Corrientes_con_datos\Corrientes_con_datos.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1632 features and 8 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 4109261 ymin: 6573007 xmax: 4522658 ymax: 6962201
## epsg (SRID): NA
## proj4string: +proj=tmerc +lat_0=-90 +lon_0=-66 +k=1 +x_0=3500000 +y_0=0 +ellps=WGS84 +units=m +no_defs
Creamos un elemento tmap que especifica un objeto de datos espaciales, al que nos referimos como āshapeā. TambiĆ©n se pueden configurar la proyección y el Ć”rea cubierta (cuadro delimitador). con tm_polygons dibujamos los poligonos del .shp.
tm_shape(shp) +
tm_polygons()
Usamos una variable.
tm_shape(shp) +
tm_polygons("viviendasp")
Cambiamos los colores, agregamos titulo, definimos los rangos (intervalos) cambiamos la leyenda.
tm_shape(shp)+
tm_polygons("viviendasp",
breaks = c(10,40,70,100,130,160,190),
palette = "BuPu",
main = "Viviendas Corrientes, segĆŗn censo 2010")+
# border.alpha = 0.5) +
tm_legend(legend.position = c("right", "bottom"))+
tm_layout(title = "Corrientes - Viviendas por radio censal, censo 2010",
title.size = 1,
title.position = c("left", "bottom"))
Agregamos la escala y En Norte en la parte superior.
tm_shape(shp)+
tm_polygons("viviendasp",
breaks = c(10,40,70,100,130,160,190),
palette = "BuPu",
main = "Viviendas Corrientes, segĆŗn censo 2010")+
# border.alpha = 0.5) +
tm_legend(legend.position = c("right", "bottom"))+
tm_layout(title = "Corrientes - Viviendas por radio censal, censo 2010",
title.size = 1,
title.position = c("left", "bottom"))+
tm_scale_bar(color.dark = "gray60",
position = c("right", "top"))+
tm_compass(type = "4star", size = 3, fontsize = 0.5,
color.dark = "gray8",text.color = "gray85",
position = c("left", "top"))