Leaflethex is primarily a proof of concept for rendering leafletJS functionality in R by running the javascript though an htmlwidget.
It also contains a function addHexbin()
for applying a hexbin layer to a leaflet map
If you are interested in using the hexbin plugin that comes along with leaflethex, the function addHexbin()
can be used which has a similar API to the rest of the Leaflet R functions that add layers to leaflet maps such as leaflet::addCircles()
, leaflet::addMarkers()
, etc.
The default use bins geopoints into hexagonal regions and used size and/or color to represent the number of points in each bin.
Radius, color, and opacity of hexagon are easily modified using arguments to addHexbin()
. As with other leaflet functions, data is inherited from the map unless specified with the data
argument.
For a more complete description of addHexbin()
, see the function help and package vignettes.
data_points <- tibble(
lat = 42.9634 + rnorm(1000),
lng = -85.6681 + rnorm(1000)
)
data_points2 <- tibble(
lat = 42.9634 + rnorm(1000),
lng = -95.6681 + rnorm(1000)
)
leaflet::leaflet(rbind(data_points, data_points2)) %>%
addTiles() %>%
addHexbin(data = data_points) %>%
addHexbin(data = data_points2,
lowEndColor = "yellow",
highEndColor = "red")