knn.graph | R Documentation |
Creates a kNN or saturated graph SpatialLinesDataFrame object
knn.graph(
x,
row.names = NULL,
k = NULL,
max.dist = NULL,
long.lat = FALSE,
drop.lower = FALSE
)
x |
sf POINTS object |
row.names |
Unique row.names assigned to results |
k |
K nearest neighbors, defaults to saturated (n(x) - 1) |
max.dist |
Maximum length of an edge (used for distance constraint) |
long.lat |
(FALSE/TRUE) Coordinates are longitude-latitude decimal degrees, in which case distances are measured in kilometers |
drop.lower |
(FALSE/TRUE) Drop lower triangle of matrix representing duplicate edges ie, from-to and to-from |
SpatialLinesDataFrame object with:
i Name of column in x with FROM (origin) index
j Name of column in x with TO (destination) index
from_ID Name of column in x with FROM (origin) region ID
to_ID Name of column in x with TO (destination) region ID
length Length of each edge (line) in projection units or kilometers if not projected
...
Jeffrey S. Evans jeffrey_evans@tnc.org and Melanie A. Murphy melanie.murphy@uwyo.edu
Murphy, M. A. & J.S. Evans. (in prep). "GenNetIt: gravity analysis in R for landscape genetics"
Murphy M.A., R. Dezzani, D.S. Pilliod & A.S. Storfer (2010) Landscape genetics of high mountain frog metapopulations. Molecular Ecology 19(17):3634-3649
library(sf)
data(ralu.site, package="GeNetIt")
# Saturated spatial graph
sat.graph <- knn.graph(ralu.site, row.names=ralu.site$SiteName)
head(sat.graph)
# Distanced constrained spatial graph
dist.graph <- knn.graph(ralu.site, row.names=ralu.site$SiteName,
max.dist = 5000)
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
plot(st_geometry(sat.graph), col="grey")
points(st_coordinates(ralu.site), col="red", pch=20, cex=1.5)
box()
title("Saturated graph")
plot(st_geometry(dist.graph), col="grey")
points(st_coordinates(ralu.site), col="red", pch=20, cex=1.5)
box()
title("Distance constrained graph")
par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.