hotspot_count {sfhotspot} | R Documentation |
Count points in cells in a two-dimensional grid
Description
Count points in cells in a two-dimensional grid
Usage
hotspot_count(
data,
cell_size = NULL,
grid_type = "rect",
grid = NULL,
weights = NULL,
quiet = FALSE
)
Arguments
data |
|
cell_size |
|
grid_type |
|
grid |
|
weights |
|
quiet |
if set to |
Details
This function counts the number of points in each cell in a regular grid. If
a column name in data
is supplied with the weights
argument,
weighted counts will also be produced.
Automatic cell-size selection
If grid
is NULL
and no cell size is given, the cell size will be set so
that there are 50 cells on the shorter side of the grid. If the data
SF
object is projected in metres or feet, the number of cells will be adjusted
upwards so that the cell size is a multiple of 100.
Value
An sf
tibble of regular grid cells with
corresponding point counts for each cell. This can be plotted using
autoplot
.
Examples
# Set cell size automatically
hotspot_count(memphis_robberies_jan)
# Transform data to UTM zone 15N so that cell_size and bandwidth can be set
# in metres
library(sf)
memphis_robberies_utm <- st_transform(memphis_robberies_jan, 32615)
# Manually set grid-cell size in metres, since the `memphis_robberies_utm`
# dataset uses a co-ordinate reference system (UTM zone 15 north) that is
# specified in metres
hotspot_count(memphis_robberies_utm, cell_size = 200)