Skip to content

Instantly share code, notes, and snippets.

@diegovalle
Created January 16, 2017 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegovalle/4f68cfc27328e78c0ee01ff7718d87f2 to your computer and use it in GitHub Desktop.
Save diegovalle/4f68cfc27328e78c0ee01ff7718d87f2 to your computer and use it in GitHub Desktop.
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