# Re: [R] how can I reorder a dendrogram?

From: Thomas Walter <Thomas.Walter_at_embl.de>
Date: Thu, 20 Mar 2008 11:39:13 +0100

Oups ... sorry, actually I found the problem.

The problem lies not with the reordering but with the construction of the dendrogram: if a hierarchical method is used, there are never more than 2 branches for a node. Therefore, the reordering does not give the expected result. I will have to try something different ...

Thanks anyway.

Thomas.

Thomas Walter wrote:

>Hi!
>
>I am trying to reorder a dendrogram via reorder.dendrogram. However, I
>observed some problems with this, and I will illustrate them with an
>example.
>
>Take the following clustering problem:
>
>datamatrix <- matrix(c(2,2,2.5,2,1.5,2,2,1.5,2,2.5,
>6,2,6.5,2,5.5,2,6,1.5,6,2.5, 4,4,4.5,4,3.5,4,4,3.5,4,4.5), ncol=2,
>byrow=TRUE)
>distmatrix <- dist(datamatrix, method="manhattan")
>hc <- hclust(distmatrix, method="single")
>dendro <- as.dendrogram(hc)
>
>The datamatrix contains three equidistant (for manhattan distance)
>clusters, each of which contains 5 points.
>Now, I want to impose an order:
>
>weights <- c(2.0, 2.0, 2.0, 2.0, 2.0, 6.0, 6.0, 6.0, 6.0, 6.0, 4.0, 4.0,
>4.0, 4.0, 4.0)
>ddd <- reorder(dendro, weights, agglo.FUN=mean)
>
>but if you compare the order of ddd with dendro, you see no change:
>
>unlist(ddd)
> [1] 15 14 13 11 12 5 4 3 1 2 10 9 8 6 7
>
>unlist(dendro)
> [1] 15 14 13 11 12 5 4 3 1 2 10 9 8 6 7
>
>I would have expected something like:
> 5 4 3 1 2 15 14 13 11 12 10 9 8 6 7
>
>or something of the sort. (I still do not know, if the order should be
>ascending or descending, but in the obtained result, it is neither nor).
>I do not see, where my mistake is ...
>
>
>Thomas.
>
>______________________________________________
>R-help_at_r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>and provide commented, minimal, self-contained, reproducible code.
>
>
>

```--
-------------------------
Thomas Walter

EMBL Heidelberg
Meyerhofstrasse 1
69117 Heidelberg
Germany

Tel: +49 (0)6221 387-8857

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help