hexbins: Get hexbins for given points and resolution

Description Usage Arguments Examples

View source: R/custom_hexbins.R

Description

Get hexbins for given points and resolution

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
hexbins(data, res = 7, ...)

## S3 method for class 'sf'
hexbins(data, res = 7, ...)

## S3 method for class 'data.frame'
hexbins(data, res = 7, lat = "lat", lng = "lng",
  ...)

## S3 method for class 'matrix'
hexbins(data, res = 7, lat = "lat", lng = "lng",
  ...)

Arguments

data

matrix, data frame (with latidude and longitude columns) or object of class sf (POINT geometry)

res

resolution of hexagons to return; number between 0 and 15

...

ignored

lat

name of latitude column

lng

name of longitude column

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(leaflet)

result <- hexbins(road_safety_greater_manchester)

pal <- colorBin("YlOrRd", domain = result$hexagons$count)

map <- leaflet(data = result$hexagons) %>%
  addProviderTiles("Stamen.Toner") %>%
  addPolygons(
    weight = 2,
    color = "white",
    fillColor = ~ pal(count),
    fillOpacity = 0.8,
    label = ~ sprintf("%i accidents", count),
    popup = result$hexagons$h3_index
  )

if (interactive()) map

crazycapivara/h3forr documentation built on Dec. 6, 2020, 5:21 a.m.