MSTSegments | R Documentation |
To identify strain in a multidimensional scaling of distances, it can be useful to plot a minimum spanning tree \insertCiteGower1966,SmithSpaceTreeDist. Colouring each edge of the tree according to its strain can identify areas where the mapping is stretched or compressed.
MSTSegments(mapping, mstEnds, ...)
StrainCol(
distances,
mapping,
mstEnds = MSTEdges(distances),
palette = rev(hcl.colors(256L, "RdYlBu"))
)
mapping |
Two-column matrix giving x and y coordinates of plotted points. |
mstEnds |
Two-column matrix identifying rows of |
... |
Additional arguments to |
distances |
Matrix or |
palette |
Vector of colours with which to colour edges. |
StrainCol()
returns a vector in which each entry is selected from
palette
, with an attribute logStrain
denoting the logarithm of the
mapped over original distance, shifted such that the median value is zero.
Palette colours are assigned centred on the median value, with entries
early in palette
assigned to edges in which the ratio of mapped
distance to original distance is small.
Martin R. Smith (martin.smith@durham.ac.uk)
Other tree space functions:
Islands()
,
MapTrees()
,
MappingQuality()
,
SpectralEigens()
,
cluster-statistics
,
median.multiPhylo()
set.seed(0)
library("TreeTools", quietly = TRUE)
distances <- ClusteringInfoDist(as.phylo(5:16, 8))
mapping <- cmdscale(distances, k = 2)
mstEnds <- MSTEdges(distances)
# Set up blank plot
plot(mapping, asp = 1, frame.plot = FALSE, ann = FALSE, axes = FALSE,
type = "n")
# Add MST
MSTSegments(mapping, mstEnds,
col = StrainCol(distances, mapping, mstEnds))
# Add points at end so they overprint the MST
points(mapping)
PlotTools::SpectrumLegend(
"bottomleft",
legend = c("Extended", "Median", "Contracted"),
bty = "n", # No box
y.intersp = 2, # Expand in Y direction
palette = hcl.colors(256L, "RdYlBu", rev = TRUE)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.