colombiaSDF <- readRDS("COL_adm1.rds")
census <- read.table(header=TRUE,file="CensoColombia2005.csv",sep =";",
colClasses=c("character", "integer", "integer", "integer"),
encoding = "UTF-8")
colombianDemo <- colombiaSDF[colombiaSDF$NAME_1 == census$Departamento, ]
colombianDemo$CCN_1 <- census$Total
colombianDemo$CCA_1 <- census$Hombres
colombianDemo$NL_NAME_1 <- census$Mujeres
pal <- colorNumeric('Reds', NULL)
my_map <- leaflet(colombianDemo) %>%
addTiles() %>%
clearShapes() %>%
addPolygons(color = "#444444",weight = 1, smoothFactor = 0.5,
fillColor = ~pal(CCN_1), fillOpacity = 0.7,
layerId = ~NAME_1,
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
label = paste(colombianDemo$NAME_1,"-",
"Men: ",colombianDemo$CCA_1,
"Women: ",colombianDemo$NL_NAME_1)) %>%
addLegend(position = 'bottomright', pal = pal,
values = colombianDemo$CCN_1, title = 'Population 2005')
my_map
RDS files can be downloaded from the URL http://www.gadm.org/country. Keep in mind, that those files are freely available only for academic use. Also the census dataset can be found in the following URL: http://www.dane.gov.co/index.php/estadisticas-por-tema/demografia-y-poblacion/censo-general-2005-1.
The repository with the files can be found in the following URL: https://github.com/ronaldraxon/RMarkdownAndLeafletProject