Learn R Programming

TreeTools (version 1.3.1)

MSTEdges: Edges of minimum spanning tree

Description

Calculate or plot the ends of each edge of the minimum spanning tree of a distance matrix.

Usage

MSTEdges(distances, plot = FALSE, x = NULL, y = NULL, ...)

Arguments

distances

Either a matrix that can be interpreted as a distance matrix, or an object of class dist.

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 distances. Necessary only if plot = TRUE.

Additional parameters to send to [lines()].

Value

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.

References

Gower1969TreeTools

See Also

Calculate minimum spanning tree: ape::mst().

Examples

Run this code
# NOT RUN {
# 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)
# }

Run the code above in your browser using DataLab