\Header{reorder}{Reorder a dendrogram}
\methalias{reorder.dendrogram}{reorder}
\keyword{manip}{reorder}
\begin{Description}\relax
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.
\end{Description}
\begin{Usage}
\begin{verbatim}
reorder(x, ...)

## S3 method for class 'dendrogram':
reorder(x, wts, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] The object to be reordered
\item[\code{wts}] The weights for reordering.
\item[\code{...}] additional arguments 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Using the weights the leaves of the dendrogram are reordered so as to
be in an order as consistent as possible with the weights.
\end{Details}
\begin{Value}
From \code{reorder.dendrogram} a dendrogram.
\end{Value}
\begin{Author}\relax
R. Gentleman
\end{Author}
\begin{SeeAlso}\relax
\code{\Link{heatmap}}, \code{\Link{cophenetic}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  set.seed(123)
  x <- rnorm(10)
  hc <- hclust(dist(x))
  dd <- as.dendrogram(hc)
  dd.reorder <- reorder(dd, 10:1)

  op <- par(mfcol = 1:2)
  plot(dd, main = "random dendrogram `dd'")
  plot(dd.reorder, main = "reorder(dd, 10:1)")
  par(op)
\end{ExampleCode}
\end{Examples}

