hotspot_change {sfhotspot} | R Documentation |
Identify change in hotspots over time
Description
Identify change in the number of points (typically representing events) between two periods (before and after a specified date) or in two groups (e.g. on weekdays or at weekends).
Usage
hotspot_change(
data,
time = NULL,
boundary = NULL,
groups = NULL,
cell_size = NULL,
grid_type = "rect",
grid = NULL,
quiet = FALSE
)
Arguments
data |
|
time |
Name of the column in |
boundary |
A single |
groups |
Name of a column in |
cell_size |
|
grid_type |
|
grid |
|
quiet |
if set to |
Details
This function creates a regular two-dimensional grid of cells (unless a
custom grid is specified with grid
) and calculates the difference
between the number of points in each grid cell:
before and after a set point in time, if
boundary
is specified,between two groups of points, if a column of grouping values is specified with
groups
,before and after the mid-point of the dates/times present in the data, if both
boundary
andgroups
areNULL
(the default).
If both boundary
and groups
are not NULL
, the value of
boundary
will be ignored.
Coverage of the output data
The grid produced by this function covers the convex hull of the input data
layer. This means the result may include zero counts for cells that are
outside the area for which data were provided, which could be misleading. To
handle this, consider cropping the output layer to the area for which data
are available. For example, if you only have crime data for a particular
district, crop the output dataset to the district boundary using
st_intersection
.
Automatic cell-size selection
If no cell size is given then 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 hot-spot classifications for each cell. This can be plotted
using autoplot
.
See Also
hotspot_dual_kde()
for comparing the density of two layers, which
will often be more useful than comparing counts if the point locations
represent and underlying continuous distribution.
Examples
# Compare counts from the first half of the period covered by the data to
# counts from the second half
hotspot_change(memphis_robberies)
# Create a grouping variable, then compare counts across values of that
# variable
memphis_robberies$weekend <-
weekdays(memphis_robberies$date) %in% c("Saturday", "Sunday")
hotspot_change(memphis_robberies, groups = weekend)