Learn R Programming

leafletCN (version 0.2.2)

leafletGeo: Create a sp object from a data.frame

Description

Function for creating a sp object from a data.frame and mapType

Usage

leafletGeo(mapName, dat = NULL, namevar = NULL, valuevar = NULL)

Arguments

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

Examples

Run this code
# NOT RUN {
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)
}
# }

Run the code above in your browser using DataLab