play_spatial | R Documentation |
Random spatial networks are created by randomly sampling nodes within a given area, and connecting them by edges according to a specified method.
play_geometric(
n,
radius,
bounds = NULL,
edges_as_lines = TRUE,
compute_length = FALSE,
...
)
n |
The number of nodes to be sampled. |
radius |
The radius within which nodes will be connected by an edge. |
bounds |
The spatial features within which the nodes should be sampled
as object of class |
edges_as_lines |
Should the created edges be spatially explicit, i.e.
have |
compute_length |
Should the geographic length of the edges be stored in
a column named |
... |
Additional arguments passed on to |
play_geometric()
: Creates a random geometric graph. Two nodes will be
connected by an edge if the distance between them is within the given radius.
If nodes are sampled on a unit square (i.e. when bounds = NULL
) this
radius is unitless. If bounds are given as a spatial feature, the radius is
assumed to be in meters for geographic coordinates, and in the units of the
coordinate reference system for projected coordinates. Alternatively, units
can also be specified explicitly by providing a units
object.
library(sf, quietly = TRUE)
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1))
# Sample 10 nodes on a unit square
# Connect nodes by an edge if they are within 0.25 distance from each other
net = play_geometric(10, 0.25)
net
plot(net)
# Sample 10 nodes within a spatial bounding box
# Connect nodes by an edge if they are within 1 km from each other
net = play_geometric(10, units::set_units(1, "km"), bounds = st_bbox(roxel))
net
plot(net)
par(oldpar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.