leafletGeo: Create a sp object from a data.frame

View source: R/leafletGeo.R

leafletGeoR Documentation

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

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)
}

Lchiffon/leafletCN documentation built on Jan. 31, 2024, 2:18 p.m.