# reorder.dendrogram

##### Reorder a Dendrogram

A method for the generic function `reorder`

.

There are many different orderings of a dendrogram that are consistent with the structure imposed. This function takes a dendrogram and a vector of values and reorders the dendrogram in the order of the supplied vector, maintaining the constraints on the dendrogram.

- Keywords
- manip

##### Usage

```
# S3 method for dendrogram
reorder(x, wts, agglo.FUN = sum, …)
```

##### Arguments

- x
the (dendrogram) object to be reordered

- wts
numeric weights (arbitrary values) for reordering.

- agglo.FUN
a function for weights agglomeration, see below.

- …
additional arguments

##### Details

Using the weights `wts`

, the leaves of the dendrogram are
reordered so as to be in an order as consistent as possible with the
weights. At each node, the branches are ordered in
increasing weights where the weight of a branch is defined as
\(f(w_j)\) where \(f\) is `agglo.FUN`

and \(w_j\) is the
weight of the \(j\)-th sub branch.

##### Value

A dendrogram where each node has a further attribute `value`

with
its corresponding weight.

##### See Also

`rev.dendrogram`

which simply reverses the nodes'
order; `heatmap`

, `cophenetic`

.

##### Examples

`library(stats)`

```
# NOT RUN {
require(graphics)
set.seed(123)
x <- rnorm(10)
hc <- hclust(dist(x))
dd <- as.dendrogram(hc)
dd.reorder <- reorder(dd, 10:1)
plot(dd, main = "random dendrogram 'dd'")
op <- par(mfcol = 1:2)
plot(dd.reorder, main = "reorder(dd, 10:1)")
plot(reorder(dd, 10:1, agglo.FUN = mean), main = "reorder(dd, 10:1, mean)")
par(op)
# }
```

*Documentation reproduced from package stats, version 3.5.0, License: Part of R 3.5.0*