
Construct a k-Nearest Neighbour Graph from Spatial Coordinates.
Source:R/DimensionalityReduction.R
kneighbors_graph.RdBuilds a sparse adjacency matrix representing the k-nearest neighbour relationships between spots or cells, using Euclidean distance between spatial coordinates.
Arguments
- location
A data frame or matrix with columns
xandyrepresenting spatial coordinates, and rownames match barcode/cell names.- n_neighbors
Integer value defining the number of neighbours to consider.
- platform
Character string being either
"Visium"or"ST", specifying the platform of the dataset being analysed. Determines how distance thresholds and adjacency are calculated whereby "Visium" data is handled slightly differently to compensate for the hexagon shape of the spots.- include_self
Boolean logical value stating whether to include self-connections (default = FALSE).
- alg
Character string specifying the algorithm to use for nearest neighbour search. Passed to
FNN::get.knn()(default = "kd_tree").