leafletGeo: Create a sp object from a data.frame

Description Usage Arguments Examples

View source: R/leafletGeo.R

Description

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

Usage

1
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

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

Example output

Loading required package: leaflet

leafletCN documentation built on May 1, 2019, 9:21 p.m.