knn.graph: Saturated or K Nearest Neighbor Graph

knn.graphR Documentation

Saturated or K Nearest Neighbor Graph

Description

Creates a kNN or saturated graph SpatialLinesDataFrame object

Usage

knn.graph(
  x,
  row.names = NULL,
  k = NULL,
  max.dist = NULL,
  long.lat = FALSE,
  drop.lower = FALSE
)

Arguments

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

Value

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

Note

...

Author(s)

Jeffrey S. Evans jeffrey_evans@tnc.org and Melanie A. Murphy melanie.murphy@uwyo.edu

References

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

Examples

 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)	  
	

GeNetIt documentation built on July 9, 2023, 5:18 p.m.

Related to knn.graph in GeNetIt...