Presentando mapas tematicos
Para presentar los mapas tematicos previamente cargamos algunas librerias tales como:
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(sp)
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(rgdal)
## 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(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(tmaptools)
Generalmente existen organizados en diversos archivos que se puede analizar espacialmente, de tal modo que, es posible isertar en formato dataframe.
A continuación, cargĆ”remos las librerĆas
library(tidyverse)
## -- Attaching packages -------------------------------------------- tidyverse 1.3.0 --
## <U+2713> ggplot2 3.3.0 <U+2713> purrr 0.3.3
## <U+2713> tibble 3.0.1 <U+2713> stringr 1.4.0
## <U+2713> tidyr 1.1.0 <U+2713> forcats 0.5.0
## <U+2713> readr 1.3.1
## -- Conflicts ----------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
Explorando datos shape
setwd("C:/Users/Usuario/Desktop/Nueva carpeta (2)")
Data <-read.csv("covid.csv")
summary(Data)
## IDDIST DISTRITO sabe.leer No.sabe.lee
## Min. :90101 ACOBAMBILLA: 1 Min. : 368 Min. : 83
## 1st Qu.:90106 ACORIA : 1 1st Qu.: 691 1st Qu.: 156
## Median :90110 ASCENSION : 1 Median : 1334 Median : 287
## Mean :90110 CONAYCA : 1 Mean : 4747 Mean :1069
## 3rd Qu.:90115 CUENCA : 1 3rd Qu.: 3142 3rd Qu.:1506
## Max. :90119 HUACHOCOLPA: 1 Max. :33507 Max. :4225
## (Other) :13
## Urbano Rural Poblacion fmasculino
## Min. : 0 Min. : 524 Min. : 524.0 Min. : 0.000
## 1st Qu.: 0 1st Qu.: 835 1st Qu.: 897.5 1st Qu.: 0.000
## Median : 0 Median : 1190 Median : 1805.0 Median : 0.000
## Mean : 3335 Mean : 3017 Mean : 6352.6 Mean : 2.316
## 3rd Qu.: 0 3rd Qu.: 2121 3rd Qu.: 4360.5 3rd Qu.: 1.000
## Max. :36975 Max. :14922 Max. :40745.0 Max. :29.000
##
## ffenenino tfallecidos Imasculino Ifemenino
## Min. :0.0000 Min. : 0.0 Min. : 0.0 Min. : 0.0
## 1st Qu.:0.0000 1st Qu.: 0.0 1st Qu.: 1.0 1st Qu.: 1.0
## Median :0.0000 Median : 0.0 Median : 6.0 Median : 3.0
## Mean :0.6842 Mean : 3.0 Mean : 101.8 Mean : 110.4
## 3rd Qu.:0.5000 3rd Qu.: 1.5 3rd Qu.: 29.5 3rd Qu.: 30.5
## Max. :6.0000 Max. :35.0 Max. :1356.0 Max. :1567.0
##
## Tinfectados Dinfectados Dfallecidos Dens.hab.km2
## Min. : 0.0 Min. : 0.0 Min. : 0.000 Min. : 2.91
## 1st Qu.: 2.5 1st Qu.: 7.0 1st Qu.: 0.000 1st Qu.: 6.90
## Median : 12.0 Median : 19.0 Median : 0.000 Median : 21.61
## Mean : 212.3 Mean : 337.7 Mean : 7.368 Mean : 29.65
## 3rd Qu.: 60.0 3rd Qu.: 103.5 3rd Qu.: 1.000 3rd Qu.: 37.06
## Max. :2923.0 Max. :4915.0 Max. :131.000 Max. :100.52
##
analisis de datos en la data frame.
Para seleccionar el municipio con mayor cantidad de habitantes
Data %>%
slice(which.max(Poblacion)) -> max_data
max_data
## IDDIST DISTRITO sabe.leer No.sabe.lee Urbano Rural Poblacion fmasculino
## 1 90101 HUANCAVELICA 33507 4225 36975 3770 40745 29
## ffenenino tfallecidos Imasculino Ifemenino Tinfectados Dinfectados
## 1 6 35 1356 1567 2923 4915
## Dfallecidos Dens.hab.km2
## 1 131 79.79
Para seleccionar el municipio el municipio con menor cantidad de habitantes
Data %>%
slice(which.min(Poblacion)) -> min_data
min_data
## IDDIST DISTRITO sabe.leer No.sabe.lee Urbano Rural Poblacion fmasculino
## 1 90115 PILCHACA 368 106 0 524 524 0
## ffenenino tfallecidos Imasculino Ifemenino Tinfectados Dinfectados
## 1 0 0 0 1 1 5
## Dfallecidos Dens.hab.km2
## 1 0 13.19
Para seleccionar los municipios con mayor cantidad de habitantes.
Data %>%
arrange(desc(Poblacion)) -> desc_data
desc_data
## IDDIST DISTRITO sabe.leer No.sabe.lee Urbano Rural Poblacion
## 1 90101 HUANCAVELICA 33507 4225 36975 3770 40745
## 2 90117 YAULI 13712 4183 5925 14922 20847
## 3 90103 ACORIA 12973 3990 5095 13823 18918
## 4 90118 ASCENSION 12359 2461 15376 709 16085
## 5 90119 HUANDO 4641 2461 0 6573 6573
## 6 90102 ACOBAMBILLA 1642 290 0 2148 2148
## 7 90114 PALCA 1387 551 0 2094 2094
## 8 90116 VILCA 1518 295 0 1998 1998
## 9 90106 HUACHOCOLPA 1495 310 0 1955 1955
## 10 90113 NUEVO OCCORO 1334 287 0 1805 1805
## 11 90105 CUENCA 865 238 0 1190 1190
## 12 90112 MOYA 789 168 0 1031 1031
## 13 90110 MANTA 750 161 0 1002 1002
## 14 90104 CONAYCA 661 153 0 898 898
## 15 90108 IZCUCHACA 721 87 0 897 897
## 16 90109 LARIA 562 159 0 773 773
## 17 90107 HUAYLLAHUARA 515 108 0 690 690
## 18 90111 MARISCAL CACERES 402 83 0 526 526
## 19 90115 PILCHACA 368 106 0 524 524
## fmasculino ffenenino tfallecidos Imasculino Ifemenino Tinfectados
## 1 29 6 35 1356 1567 2923
## 2 1 0 1 70 65 135
## 3 6 0 6 44 37 81
## 4 4 2 6 357 334 691
## 5 0 1 1 34 33 67
## 6 1 3 4 13 3 16
## 7 1 1 2 3 11 14
## 8 1 0 1 1 2 3
## 9 1 0 1 25 28 53
## 10 0 0 0 6 1 7
## 11 0 0 0 1 0 1
## 12 0 0 0 7 3 10
## 13 0 0 0 1 1 2
## 14 0 0 0 3 2 5
## 15 0 0 0 5 7 12
## 16 0 0 0 0 0 0
## 17 0 0 0 0 0 0
## 18 0 0 0 9 3 12
## 19 0 0 0 0 1 1
## Dinfectados Dfallecidos Dens.hab.km2
## 1 4915 131 79.79
## 2 248 2 65.03
## 3 174 3 34.80
## 4 698 1 39.33
## 5 147 0 33.62
## 6 12 0 2.91
## 7 17 1 25.89
## 8 9 0 6.47
## 9 60 1 5.79
## 10 21 0 7.33
## 11 0 0 21.61
## 12 32 0 10.90
## 13 2 0 6.31
## 14 11 0 21.67
## 15 46 1 72.63
## 16 0 0 12.00
## 17 0 0 3.53
## 18 19 0 100.52
## 19 5 0 13.19
Para seleccionar los municipios con menor cantidad de habitantes.
Data %>%
arrange((Poblacion)) -> asc_data
asc_data
## IDDIST DISTRITO sabe.leer No.sabe.lee Urbano Rural Poblacion
## 1 90115 PILCHACA 368 106 0 524 524
## 2 90111 MARISCAL CACERES 402 83 0 526 526
## 3 90107 HUAYLLAHUARA 515 108 0 690 690
## 4 90109 LARIA 562 159 0 773 773
## 5 90108 IZCUCHACA 721 87 0 897 897
## 6 90104 CONAYCA 661 153 0 898 898
## 7 90110 MANTA 750 161 0 1002 1002
## 8 90112 MOYA 789 168 0 1031 1031
## 9 90105 CUENCA 865 238 0 1190 1190
## 10 90113 NUEVO OCCORO 1334 287 0 1805 1805
## 11 90106 HUACHOCOLPA 1495 310 0 1955 1955
## 12 90116 VILCA 1518 295 0 1998 1998
## 13 90114 PALCA 1387 551 0 2094 2094
## 14 90102 ACOBAMBILLA 1642 290 0 2148 2148
## 15 90119 HUANDO 4641 2461 0 6573 6573
## 16 90118 ASCENSION 12359 2461 15376 709 16085
## 17 90103 ACORIA 12973 3990 5095 13823 18918
## 18 90117 YAULI 13712 4183 5925 14922 20847
## 19 90101 HUANCAVELICA 33507 4225 36975 3770 40745
## fmasculino ffenenino tfallecidos Imasculino Ifemenino Tinfectados
## 1 0 0 0 0 1 1
## 2 0 0 0 9 3 12
## 3 0 0 0 0 0 0
## 4 0 0 0 0 0 0
## 5 0 0 0 5 7 12
## 6 0 0 0 3 2 5
## 7 0 0 0 1 1 2
## 8 0 0 0 7 3 10
## 9 0 0 0 1 0 1
## 10 0 0 0 6 1 7
## 11 1 0 1 25 28 53
## 12 1 0 1 1 2 3
## 13 1 1 2 3 11 14
## 14 1 3 4 13 3 16
## 15 0 1 1 34 33 67
## 16 4 2 6 357 334 691
## 17 6 0 6 44 37 81
## 18 1 0 1 70 65 135
## 19 29 6 35 1356 1567 2923
## Dinfectados Dfallecidos Dens.hab.km2
## 1 5 0 13.19
## 2 19 0 100.52
## 3 0 0 3.53
## 4 0 0 12.00
## 5 46 1 72.63
## 6 11 0 21.67
## 7 2 0 6.31
## 8 32 0 10.90
## 9 0 0 21.61
## 10 21 0 7.33
## 11 60 1 5.79
## 12 9 0 6.47
## 13 17 1 25.89
## 14 12 0 2.91
## 15 147 0 33.62
## 16 698 1 39.33
## 17 174 3 34.80
## 18 248 2 65.03
## 19 4915 131 79.79
Para importar datos vectoriales
setwd("E:/Clases R/Huancavelica/datos shape")
list.files(path=".")
## [1] "25m" "26m" "cuencamantaro.dbf"
## [4] "cuencamantaro.prj" "cuencamantaro.shp" "cuencamantaro.shx"
## [7] "Datosgeoquimica.dbf" "Datosgeoquimica.prj" "Datosgeoquimica.shp"
## [10] "Datosgeoquimica.shx" "Departamento.dbf" "Departamento.prj"
## [13] "Departamento.shp" "Departamento.shx" "Distrito.dbf"
## [16] "Distrito.mshp" "Distrito.prj" "Distrito.shp"
## [19] "Distrito.shx" "EI.dbf" "EI.prj"
## [22] "EI.shp" "EI.shx" "muni.cpg"
## [25] "muni.dbf" "muni.prj" "muni.shp"
## [28] "muni.shx" "muni1.cpg" "muni1.dbf"
## [31] "muni1.mshp" "muni1.prj" "muni1.shp"
## [34] "muni1.shx" "municipio.dbf" "municipio.mshp"
## [37] "municipio.prj" "municipio.shp" "municipio.shx"
## [40] "municipiodb.dbf" "municipiodb.mshp" "municipiodb.prj"
## [43] "municipiodb.shp" "municipiodb.shx" "Provi.dbf"
## [46] "Provi.prj" "Provi.shp" "Provi.shx"
## [49] "Puntosedu.dbf" "Puntosedu.prj" "Puntosedu.shp"
## [52] "Puntosedu.shx"
Importamos el dato que nos interesa mediente el siguiente codigo.
muni <- st_read("E:/Clases R/Huancavelica/datos shape/Distrito.shp")
## Reading layer `Distrito' from data source `E:\Clases R\Huancavelica\datos shape\Distrito.shp' using driver `ESRI Shapefile'
## Simple feature collection with 19 features and 4 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 437056 ymin: 8542334 xmax: 534343 ymax: 8633600
## projected CRS: Transverse_Mercator
muni
## Simple feature collection with 19 features and 4 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 437056 ymin: 8542334 xmax: 534343 ymax: 8633600
## projected CRS: Transverse_Mercator
## First 10 features:
## IDDIST DISTRITO FUENTE Area geometry
## 1 090103 ACORIA INEI 543581483 POLYGON ((529300.7 8604073,...
## 2 090106 HUACHOCOLPA INEI 337581696 POLYGON ((509708.3 8547399,...
## 3 090118 ASCENSION INEI 408938070 POLYGON ((463550.3 8569856,...
## 4 090104 CONAYCA INEI 41434621 POLYGON ((494810.7 8618271,...
## 5 090108 IZCUCHACA INEI 12349669 POLYGON ((501398 8617719, 5...
## 6 090113 NUEVO OCCORO INEI 246027644 POLYGON ((498516 8610059, 4...
## 7 090117 YAULI INEI 320572643 POLYGON ((532565.5 8580141,...
## 8 090114 PALCA INEI 80876297 POLYGON ((503644.1 8605267,...
## 9 090102 ACOBAMBILLA INEI 736862728 POLYGON ((453214.2 8604176,...
## 10 090110 MANTA INEI 158582729 POLYGON ((484906.6 8615428,...
Para unir la data frame con el dato vectorial, (join to relacion) para ello es importante tener datos en comun como por ejemplo:
Data$DISTRITO
## [1] ACOBAMBILLA ACORIA ASCENSION CONAYCA
## [5] CUENCA HUACHOCOLPA HUANCAVELICA HUANDO
## [9] HUAYLLAHUARA IZCUCHACA LARIA MANTA
## [13] MARISCAL CACERES MOYA NUEVO OCCORO PALCA
## [17] PILCHACA VILCA YAULI
## 19 Levels: ACOBAMBILLA ACORIA ASCENSION CONAYCA CUENCA ... YAULI
class(muni)
## [1] "sf" "data.frame"
class(muni$DISTRITO)
## [1] "factor"
Despues de corroborarla existencia de los datos en comun se utiliza el siguiente codigo para hacer el join to relation.
dato <- merge(muni, Data, by.x="DISTRITO",by.y="DISTRITO")
summary(dato)
## DISTRITO IDDIST.x FUENTE Area IDDIST.y
## ACOBAMBILLA: 1 090101 : 1 INEI:19 Min. : 5232390 Min. :90101
## ACORIA : 1 090102 : 1 1st Qu.: 48248281 1st Qu.:90106
## ASCENSION : 1 090103 : 1 Median :158582729 Median :90110
## CONAYCA : 1 090104 : 1 Mean :220888453 Mean :90110
## CUENCA : 1 090105 : 1 3rd Qu.:329077169 3rd Qu.:90115
## HUACHOCOLPA: 1 090106 : 1 Max. :736862728 Max. :90119
## (Other) :13 (Other):13
## sabe.leer No.sabe.lee Urbano Rural
## Min. : 368 Min. : 83 Min. : 0 Min. : 524
## 1st Qu.: 691 1st Qu.: 156 1st Qu.: 0 1st Qu.: 835
## Median : 1334 Median : 287 Median : 0 Median : 1190
## Mean : 4747 Mean :1069 Mean : 3335 Mean : 3017
## 3rd Qu.: 3142 3rd Qu.:1506 3rd Qu.: 0 3rd Qu.: 2121
## Max. :33507 Max. :4225 Max. :36975 Max. :14922
##
## Poblacion fmasculino ffenenino tfallecidos
## Min. : 524.0 Min. : 0.000 Min. :0.0000 Min. : 0.0
## 1st Qu.: 897.5 1st Qu.: 0.000 1st Qu.:0.0000 1st Qu.: 0.0
## Median : 1805.0 Median : 0.000 Median :0.0000 Median : 0.0
## Mean : 6352.6 Mean : 2.316 Mean :0.6842 Mean : 3.0
## 3rd Qu.: 4360.5 3rd Qu.: 1.000 3rd Qu.:0.5000 3rd Qu.: 1.5
## Max. :40745.0 Max. :29.000 Max. :6.0000 Max. :35.0
##
## Imasculino Ifemenino Tinfectados Dinfectados
## Min. : 0.0 Min. : 0.0 Min. : 0.0 Min. : 0.0
## 1st Qu.: 1.0 1st Qu.: 1.0 1st Qu.: 2.5 1st Qu.: 7.0
## Median : 6.0 Median : 3.0 Median : 12.0 Median : 19.0
## Mean : 101.8 Mean : 110.4 Mean : 212.3 Mean : 337.7
## 3rd Qu.: 29.5 3rd Qu.: 30.5 3rd Qu.: 60.0 3rd Qu.: 103.5
## Max. :1356.0 Max. :1567.0 Max. :2923.0 Max. :4915.0
##
## Dfallecidos Dens.hab.km2 geometry
## Min. : 0.000 Min. : 2.91 POLYGON :19
## 1st Qu.: 0.000 1st Qu.: 6.90 epsg:NA : 0
## Median : 0.000 Median : 21.61 +proj=utm ...: 0
## Mean : 7.368 Mean : 29.65
## 3rd Qu.: 1.000 3rd Qu.: 37.06
## Max. :131.000 Max. :100.52
##
dato
## Simple feature collection with 19 features and 19 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 437056 ymin: 8542334 xmax: 534343 ymax: 8633600
## projected CRS: Transverse_Mercator
## First 10 features:
## DISTRITO IDDIST.x FUENTE Area IDDIST.y sabe.leer No.sabe.lee Urbano
## 1 ACOBAMBILLA 090102 INEI 736862728 90102 1642 290 0
## 2 ACORIA 090103 INEI 543581483 90103 12973 3990 5095
## 3 ASCENSION 090118 INEI 408938070 90118 12359 2461 15376
## 4 CONAYCA 090104 INEI 41434621 90104 661 153 0
## 5 CUENCA 090105 INEI 55061940 90105 865 238 0
## 6 HUACHOCOLPA 090106 INEI 337581696 90106 1495 310 0
## 7 HUANCAVELICA 090101 INEI 510635020 90101 33507 4225 36975
## 8 HUANDO 090119 INEI 195481431 90119 4641 2461 0
## 9 HUAYLLAHUARA 090107 INEI 36415891 90107 515 108 0
## 10 IZCUCHACA 090108 INEI 12349669 90108 721 87 0
## Rural Poblacion fmasculino ffenenino tfallecidos Imasculino Ifemenino
## 1 2148 2148 1 3 4 13 3
## 2 13823 18918 6 0 6 44 37
## 3 709 16085 4 2 6 357 334
## 4 898 898 0 0 0 3 2
## 5 1190 1190 0 0 0 1 0
## 6 1955 1955 1 0 1 25 28
## 7 3770 40745 29 6 35 1356 1567
## 8 6573 6573 0 1 1 34 33
## 9 690 690 0 0 0 0 0
## 10 897 897 0 0 0 5 7
## Tinfectados Dinfectados Dfallecidos Dens.hab.km2
## 1 16 12 0 2.91
## 2 81 174 3 34.80
## 3 691 698 1 39.33
## 4 5 11 0 21.67
## 5 1 0 0 21.61
## 6 53 60 1 5.79
## 7 2923 4915 131 79.79
## 8 67 147 0 33.62
## 9 0 0 0 3.53
## 10 12 46 1 72.63
## geometry
## 1 POLYGON ((453214.2 8604176,...
## 2 POLYGON ((529300.7 8604073,...
## 3 POLYGON ((463550.3 8569856,...
## 4 POLYGON ((494810.7 8618271,...
## 5 POLYGON ((493970.2 8628863,...
## 6 POLYGON ((509708.3 8547399,...
## 7 POLYGON ((494817.7 8572250,...
## 8 POLYGON ((506099.8 8614501,...
## 9 POLYGON ((483639.1 8629628,...
## 10 POLYGON ((501398 8617719, 5...
Le damos para transformar el sistema de referencia en este caso WGS 84 Zona 18L sur.
Dato1 <- st_transform(dato, crs = 7369)
Dato1
## Simple feature collection with 19 features and 19 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 1295142 ymin: -5936377 xmax: 1394088 ymax: -5842589
## projected CRS: NAD83(2011) / InGCS Wells (m)
## First 10 features:
## DISTRITO IDDIST.x FUENTE Area IDDIST.y sabe.leer No.sabe.lee Urbano
## 1 ACOBAMBILLA 090102 INEI 736862728 90102 1642 290 0
## 2 ACORIA 090103 INEI 543581483 90103 12973 3990 5095
## 3 ASCENSION 090118 INEI 408938070 90118 12359 2461 15376
## 4 CONAYCA 090104 INEI 41434621 90104 661 153 0
## 5 CUENCA 090105 INEI 55061940 90105 865 238 0
## 6 HUACHOCOLPA 090106 INEI 337581696 90106 1495 310 0
## 7 HUANCAVELICA 090101 INEI 510635020 90101 33507 4225 36975
## 8 HUANDO 090119 INEI 195481431 90119 4641 2461 0
## 9 HUAYLLAHUARA 090107 INEI 36415891 90107 515 108 0
## 10 IZCUCHACA 090108 INEI 12349669 90108 721 87 0
## Rural Poblacion fmasculino ffenenino tfallecidos Imasculino Ifemenino
## 1 2148 2148 1 3 4 13 3
## 2 13823 18918 6 0 6 44 37
## 3 709 16085 4 2 6 357 334
## 4 898 898 0 0 0 3 2
## 5 1190 1190 0 0 0 1 0
## 6 1955 1955 1 0 1 25 28
## 7 3770 40745 29 6 35 1356 1567
## 8 6573 6573 0 1 1 34 33
## 9 690 690 0 0 0 0 0
## 10 897 897 0 0 0 5 7
## Tinfectados Dinfectados Dfallecidos Dens.hab.km2
## 1 16 12 0 2.91
## 2 81 174 3 34.80
## 3 691 698 1 39.33
## 4 5 11 0 21.67
## 5 1 0 0 21.61
## 6 53 60 1 5.79
## 7 2923 4915 131 79.79
## 8 67 147 0 33.62
## 9 0 0 0 3.53
## 10 12 46 1 72.63
## geometry
## 1 POLYGON ((1311626 -5871364,...
## 2 POLYGON ((1388844 -5874521,...
## 3 POLYGON ((1320716 -5906581,...
## 4 POLYGON ((1354386 -5858724,...
## 5 POLYGON ((1353952 -5847939,...
## 6 POLYGON ((1366623 -5931279,...
## 7 POLYGON ((1352535 -5905435,...
## 8 POLYGON ((1365697 -5863000,...
## 9 POLYGON ((1343497 -5846756,...
## 10 POLYGON ((1361052 -5859546,...
Para hacer la presentacion del mapa tematico, adicionalmente nos aseguramos en cargar las librerias
library(tmap)
## Warning: replacing previous import 'sf::st_make_valid' by
## 'lwgeom::st_make_valid' when loading 'tmap'
library(leaflet)
Ejecutamos el siguiente codigo
qtm(Dato1, fill = "Dinfectados")
La otra opcion es utilizando el siguiente codigo.
tm_shape(Dato1) + tm_fill("Dinfectados")
Para seleccionar otros colores cargamos la libreria RColorBrewer
library(RColorBrewer)
display.brewer.all()
Para asignar los colores
tm_shape(Dato1) + tm_fill("Dinfectados", palette = "Blues")
Eligiendo los intervalos de los estilos, āquantileā, āequalā ,āprettyā, ājenksā
tm_shape(Dato1) + tm_fill("Dinfectados", style = "quantile", palette = "Blues")
Agregamos numero de niveles, n = 10
tm_shape(Dato1) + tm_fill("Dinfectados", style = "quantile", n = 10,
palette = "Blues")
Agregamos los niveles en la incluye el histogrma, el borde, norte magentetico y la escala.
tm_shape(Dato1) + tm_fill("Dinfectados", style = "quantile", n = 10,
palette = "Blues", legend.hist = FALSE)+
tm_borders(alpha=.4)+ tm_compass(position = c("left", "top"))+
tm_scale_bar(position = c("left", "bottom"))
Insertamos la graticula, el etiquetado y el titulo del mapa.
tm_shape(Dato1) + tm_fill("Dinfectados", style = "quantile", n = 10,
palette = "Blues", legend.hist = FALSE)+
tm_borders(alpha=.4)+ tm_compass(position = c("left", "top"))+
tm_scale_bar(position = c("right", "bottom"))+
tm_layout(panel.labels=c("Mapa de infectados covid Prov. Huancavelica"),legend.outside=FALSE)+
tm_text("DISTRITO", size= 0.35)+
tm_graticules(n.x=4,n.y=4, lines = TRUE, labels.rot = c(0, 90))
Insertamos un vertor adicional al mapa
tm_shape(Dato1) + tm_fill("Dinfectados", style = "quantile", n = 15,
palette = "Blues", legend.hist = FALSE )+
tm_shape(Dato1)+
tm_bubbles(size="Dens.hab.km2", style = "quantile", n = 10, title.size = "Dens.hab.km2")+
tm_compass(position = c("left", "top"))+
tm_scale_bar(position = c("left", "bottom"))+
tm_layout(panel.labels=c("Mapa infectados covid Huancavelica"),legend.outside=TRUE)+
tm_text("DISTRITO", size= 0.35)+
tm_graticules(n.x=4,n.y=4, lines = FALSE, labels.rot = c(0, 90))