I live in Colombia, we have a 33 departments as political division.
I download data from http://datosabiertos.esri.co/datasets/0611d10c1a4d4cab82bd10dd81874c43_0 and learn how load geoJSON from http://rstudio.github.io/leaflet/json.html.
setwd("C:\\Users\\juanc\\Dropbox\\DataScience\\Data products")
library(leaflet)
library(jsonlite)
geojson <- readLines("json/deptopob3.geojson", warn = FALSE) %>%
paste(collapse = "\n") %>%
fromJSON(simplifyVector = FALSE)
population <- sapply(geojson$features, function(feat) {
feat$properties$G_HOMB + feat$properties$G_MUJER
})
pal <- colorNumeric(
palette = "RdYlBu",
domain = population
)
geojson$features <- lapply(geojson$features, function(feat) {
feat$properties$style <- list(fillColor = pal(feat$properties$G_HOMB + feat$properties$G_MUJER))
feat
})
leaflet() %>% setView(lng = -75.603829, lat = 4.984268, zoom = 5) %>% addGeoJSON(geojson) %>%
addLegend("bottomright", pal = pal, values = population,
title = "Population (2005)",
labFormat = labelFormat(prefix = ""),
opacity = 1
)