Created
January 16, 2017 18:20
-
-
Save diegovalle/4f68cfc27328e78c0ee01ff7718d87f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("dplyr") | |
library("mxmaps") | |
library("geojsonio") | |
library("jsonlite") | |
library("leaflet") | |
# Convert the topoJSON to spatial object | |
tmpdir <- tempdir() | |
# have to use RJSONIO or else the topojson isn't valid | |
write(RJSONIO::toJSON(mxmunicipio.topoJSON), file.path(tmpdir, "mun.topojson")) | |
muns <- topojson_read(file.path(tmpdir, "mun.topojson")) | |
#random municipios in Nuevo León | |
monterrey <- muns[muns$id %in% c(19039:19045),] | |
#random data | |
monterrey@data$rand <- 1:7 | |
# Create a continuous palette function | |
pal <- colorNumeric( | |
palette = "Blues", | |
domain = monterrey@data$rand | |
) | |
leaflet(monterrey) %>% | |
addPolygons(stroke = FALSE, smoothFactor = 0.2, fillOpacity = 1, | |
color = ~pal(monterrey@data$rand) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment