Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.