knn.graph {GeNetIt}R 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:

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)	  
	

[Package GeNetIt version 0.1-6 Index]