vegan (version 2.4-2)

reorder.hclust: Reorder a Hierarchical Clustering Tree

Description

Function takes a hierarchical clustering tree from hclust and a vector of values and reorders the clustering tree in the order of the supplied vector, maintaining the constraints on the tree. This is a method of generic function reorder and an alternative to reordering a "dendrogram" object with reorder.dendrogram

Usage

"reorder"(x, wts, agglo.FUN = c("mean", "min", "max", "sum", "uwmean"), ...) "rev"(x) "scores"(x, display = "internal", ...)

Arguments

x
hierarchical clustering from hclust.
wts
numeric vector for reordering.
agglo.FUN
a function for weights agglomeration, see below.
display
return "internal" nodes or "terminal" nodes (also called "leaves").
...
additional arguments (ignored).

Value

Reordered hclust result object with added item value that gives the value of the statistic at each merge level.

Details

Dendrograms can be ordered in many ways. The reorder function reorders an hclust tree and provides an alternative to reorder.dendrogram which can reorder a dendrogram. The current function will also work differently when the agglo.FUN is "mean": the reorder.dendrogram will always take the direct mean of member groups ignoring their sizes, but this function will used weighted.mean weighted by group sizes, so that the group mean is always the mean of member leaves (terminal nodes). If you want to ignore group sizes, you can use unweighted mean with "uwmean".

The function accepts only a limited list of agglo.FUN functions for assessing the value of wts for groups. The ordering is always ascending, but the order of leaves can be reversed with rev.

Function scores finds the coordinates of nodes as a two-column matrix. For terminal nodes (leaves) this the value at which the item is merged to the tree, and the labels can still hang below this level (see plot.hclust).

See Also

hclust for getting clustering trees, as.hclust.spantree to change a vegan minimum spanning tree to an hclust object, and dendrogram and reorder.dendrogram for an alternative implementation.

Examples

Run this code
## reorder by water content of soil
data(mite, mite.env)
hc <- hclust(vegdist(wisconsin(sqrt(mite))))
ohc <- with(mite.env, reorder(hc, WatrCont))
plot(hc)
plot(ohc)

## label leaves by the observed value, and each branching point
## (internal node) by the cluster mean
with(mite.env, plot(ohc, labels=round(WatrCont), cex=0.7))
ordilabel(scores(ohc), label=round(ohc$value), cex=0.7)

## Slightly different from reordered 'dendrogram' which ignores group
## sizes in assessing means.
den <- as.dendrogram(hc)
den <- with(mite.env, reorder(den, WatrCont, agglo.FUN = mean))
plot(den)

Run the code above in your browser using DataCamp Workspace