Reorder a Hierarchical Clustering Tree
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
1 2 3 4 5 6 7
hierarchical clustering from
numeric vector for reordering.
a function for weights agglomeration, see below.
additional arguments (ignored).
Dendrograms can be ordered in many ways. The
hclust tree and provides an alternative to
reorder.dendrogram which can reorder a
dendrogram. The current function will also work
differently when 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
The function accepts only a limited list of
functions for assessing the value of
wts for groups. The
ordering is always ascending, but the order of leaves can be
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
hclust result object with added item
value that gives the value of the statistic at each merge
These functions should really be in base R.
hclust for getting clustering trees,
as.hclust.spantree to change a vegan minimum
spanning tree to an
hclust object, and
reorder.dendrogram for an
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
## 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)
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.