addHexbin: Add a Hexbin layer

View source: R/hexbin.R

addHexbinR Documentation

Add a Hexbin layer

Description

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

lat

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

Radius of the hexbin layer

layerId

the layer id

group

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

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 data object provided to leaflet() initially, but can be overridden

Value

the new map object

Note

Currently doesn't respect layerId nor group.

References

https://github.com/bluehalo/leaflet-d3#hexbins-api

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

leaflet.extras2 documentation built on Aug. 21, 2023, 5:08 p.m.