Description Usage Arguments Examples
Function for creating a sp object from a data.frame and mapType
1 | leafletGeo(mapName, dat = NULL, namevar = NULL, valuevar = NULL)
|
mapName |
mapName for loading, eg. 'china', 'city', ... |
dat |
a data.frame contain regions and values |
namevar |
show which feature is chosen for name variable |
valuevar |
show which featue is chosen for value variable |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | if(require(leaflet)){
dat = data.frame(regionNames("china"),
runif(34))
map = leafletGeo("china", dat)
pal <- colorNumeric(
palette = "Blues",
domain = map$value)
leaflet(map) %>% addTiles() %>%
addPolygons(stroke = TRUE,
smoothFactor = 1,
fillOpacity = 0.7,
weight = 1,
color = ~pal(value),
popup = ~htmltools::htmlEscape(popup)
) %>%
addLegend("bottomright", pal = pal, values = ~value,
title = "legendTitle",
labFormat = leaflet::labelFormat(prefix = ""),
opacity = 1)
}
|
Loading required package: leaflet
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.