| MSTEdges {TreeTools} | R Documentation |
Calculate or plot the ends of each edge of the minimum spanning tree of a distance matrix.
MSTEdges(distances, plot = FALSE, x = NULL, y = NULL, ...)
distances |
Either a matrix that can be interpreted as a distance
matrix, or an object of class |
plot |
Logical specifying whether to add the minimum spanning tree to an existing plot. |
x, y |
Numeric vectors specifying the X and Y coordinates of each
element in |
... |
Additional parameters to send to |
MSTEdges() returns a matrix in which each row corresponds to an
edge of the minimum spanning tree, and each column lists the index of the
entry in distances at which the line begins and ends.
Martin R. Smith (martin.smith@durham.ac.uk)
Gower JC, Ross GJS (1969). “Minimum spanning trees and single linkage cluster analysis.” Journal of the Royal Statistical Society. Series C (Applied Statistics), 18(1), 54–64. doi: 10.2307/2346439.
Calculate minimum spanning tree: ape::mst().
# Corners of an almost-regular octahedron
points <- matrix(c(0, 0, 2, 2, 1.1, 1,
0, 2, 0, 2, 1, 1.1,
0, 0, 0, 0, 1, -1), 6)
distances <- dist(points)
MSTEdges(distances)
plot(points[, 1:2], ann = FALSE, asp = 1)
MSTEdges(distances, TRUE, x = points[, 1], y = points[, 2], lwd = 2)