Learn R Programming

leafletCN (version 0.2.2)

geojsonMap: Load amap to leaflet

Description

Simple function like addTiles()

Usage

geojsonMap(dat, mapName, namevar=NULL, valuevar=NULL,
  palette = "Blues", colorMethod = "numeric",
  na.color = "#808080", popup = NULL, stroke = T, smoothFactor = 1,
   weight = 1, fillOpacity = 0.7, legendTitle = "Legend", tileType, ...)

Arguments

dat

a data.frame contain regions and values

mapName

mapName for loading, eg. 'china', 'city', ...

namevar

a formula show which feature is chosen for name variable

valuevar

a formula show which feature is chosen for value variable

palette

The colors or color function that values will be mapped to, see RColorBrewer::display.brewer.all()

colorMethod

set one of the coloe mapping in c("numeric", "bin", "quantile", "Factor")

na.color

The color to return for NA values. Note that na.color=NA is valid.

popup

a character vector of the HTML content for the popups (you are recommended to escape the text using htmlEscape() for security reasons)

stroke

whether to draw stroke along the path (e.g. the borders of polygons or circles)

smoothFactor

how much to simplify the polyline on each zoom level (more means better performance and less accurate representation)

weight

stroke width in pixels

fillOpacity

fill opacity

legendTitle

legend title

tileType

function to define tile like amap or leaflet::addTiles

...

other paramter pass to the color mapping function

Examples

Run this code
# NOT RUN {
dat = data.frame(name = regionNames("china"),
                 value = runif(34))
geojsonMap(dat,"china")

dat$value2 = cut(dat$value, c(0, 0.25, 0.5, 1))
geojsonMap(dat,"china",
  namevar = ~name,
  valuevar = ~value2,
  palette="Reds",
  colorMethod="factor")

geojsonMap(dat,"china",
  namevar = ~name,
  valuevar = ~value2,
  palette = topo.colors(3),
  colorMethod="factor")
# }

Run the code above in your browser using DataLab