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.
addHexbin(
map,
lng = NULL,
lat = NULL,
radius = 20,
layerId = NULL,
group = NULL,
opacity = 0.5,
options = hexbinOptions(),
data = getMapData(map)
)
a map widget object created from leaflet()
a numeric vector of longitudes, or a one-sided formula of the form
~x
where x
is a variable in data
; by default (if not
explicitly provided), it will be automatically inferred from data
by
looking for a column named lng
, long
, or longitude
(case-insensitively)
a vector of latitudes or a formula (similar to the lng
argument; the names lat
and latitude
are used when guessing
the latitude column from data
)
Radius of the hexbin layer
the layer id
the name of the group the newly created layers should belong to
(for clearGroup
and addLayersControl
purposes).
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 of the hexbin layer
List of further options. See hexbinOptions
the data object from which the argument values are derived; by
default, it is the data
object provided to leaflet()
initially, but can be overridden
the new map
object
Currently doesn't respect layerId
nor group
.
Other Hexbin-D3 Functions:
clearHexbin()
,
hexbinOptions()
,
hideHexbin()
,
showHexbin()
,
updateHexbin()
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)
))