Create dynamic hexbin-based heatmaps on Leaflet maps. This plugin leverages the data-binding power of d3 to allow you to dynamically update the data and visualize the transitions.
Usage
addHexbin(
map,
lng = NULL,
lat = NULL,
radius = 20,
layerId = NULL,
group = NULL,
opacity = 0.5,
options = hexbinOptions(),
data = getMapData(map)
)Arguments
- map
a map widget object created from
leaflet()- lng
a numeric vector of longitudes, or a one-sided formula of the form
~xwherexis a variable indata; by default (if not explicitly provided), it will be automatically inferred fromdataby looking for a column namedlng,long, orlongitude(case-insensitively)- lat
a vector of latitudes or a formula (similar to the
lngargument; the nameslatandlatitudeare used when guessing the latitude column fromdata)- radius
Radius of the hexbin layer
- layerId
the layer id
- group
the name of the group the newly created layers should belong to (for
clearGroupandaddLayersControlpurposes). Human-friendly group names are permitted–they need not be short, identifier-style names. Any number of layers and even different types of layers (e.g. markers and polygons) can share the same group name.- opacity
Opacity of the hexbin layer
- options
List of further options. See
hexbinOptions- data
the data object from which the argument values are derived; by default, it is the
dataobject provided toleaflet()initially, but can be overridden
See also
Other Hexbin-D3 Functions:
clearHexbin(),
hexbinOptions(),
hideHexbin(),
showHexbin(),
updateHexbin()
Examples
library(leaflet)
library(leaflet.extras2)
n <- 1000
df <- data.frame(
lat = rnorm(n, 42.0285, .01),
lng = rnorm(n, -93.65, .01)
)
leaflet() %>%
addTiles() %>%
addHexbin(
lng = df$lng, lat = df$lat,
options = hexbinOptions(
colorRange = c("red", "yellow", "blue"),
radiusRange = c(10, 20)
)
)