deme_graph: Lightweight deme / landscape graph from coordinates

View source: R/deme_graph.R

deme_graphR Documentation

Lightweight deme / landscape graph from coordinates

Description

Builds the minimal spatial graph that landscape-genetic network methods use: a set of vertex coordinates and an undirected edge list. For deme-scale problems (dozens to a few hundred nodes) this avoids the heavier raster / conductance graph builders, and the returned object is interchangeable with a terradish_graph.

Usage

deme_graph(
  coords,
  neighbours = c("delaunay", "knn", "lattice"),
  k = 6L,
  queen = FALSE
)

Arguments

coords

A two-column numeric matrix or data frame of node (deme) coordinates, one row per node (columns x, y).

neighbours

Edge construction. "delaunay" (the Delaunay triangulation; needs the deldir package), "knn" (symmetric k-nearest-neighbour adjacency), or "lattice" (rook or queen adjacency for points lying on an integer grid).

k

Number of neighbours for neighbours = "knn".

queen

For neighbours = "lattice", also connect diagonal (queen) neighbours; the default rook adjacency reproduces conductance_surface(directions = 4).

Value

An object of class c("landgraph", "terradish_graph") with vertex_coordinates (an n x 2 matrix), edge_pairs (an m x 2 integer matrix of 1-based undirected edges, each pair once, a < b), and n_vertices.

See Also

edge_gradient, edge_flow

Examples

coords <- as.matrix(expand.grid(x = 0:4, y = 0:4))
g <- deme_graph(coords, neighbours = "lattice")
nrow(g$edge_pairs)

landgraph documentation built on Sept. 26, 2026, 1:08 a.m.