Skip to content
Back to formatted view

Raw Message

Message-ID: <43A0314A.10750.CFF473@localhost>
Date: 2005-12-14T13:50:50Z
From: Dr. Herwig Meschke
Subject: dendrogram: how to obtain leaf height
In-Reply-To: <BE216486E4154040BF783AE5DAAA3ED401C2D1AB@SRVEXCH1.cnio.es>

try

height.of.leafs <- dendrapply(hcd, function(e) attr(e, "height"))
unlist(height.of.leafs)

Regards
Herwig

-- 
Dr. Herwig Meschke
Wissenschaftliche Beratung
Hagsbucher Weg 27
D-89150 Laichingen

phone +49 7333 210 417 / fax +49 7333 210 418
email HerwigMeschke at t-online.de

On 12 Dec 2005 at 21:15, Diaz.Ramon wrote:

> Dear All,
> 
> How can the height of a leaf be extracted from a dendrogram? 
> 
> Sure, I can print it, but I am not able to, say, store it in an object. I think I understand that the height is a 
property of the split, not the leaf itself, but the printing functions display a "height" or "h" (which changes with 
"hang") and that is what I want. Obviously, the info is there (e.g., "str(dendrogram)"), I just don't see how to 
obtain it as I want.
> 
> 
> 
> hc <- hclust(dist(USArrests), "ave")
> hcd <- as.dendrogram(hc, hang = 0.001)
> 
> 
> dendrapply(rev(hcd), hnode)
> 
> ## None of the following work as I want
> 
> hnode <- function(x) {
>     ## nothing
>     if (is.leaf(x))
>         print(x$height)
> }
> 
> 
> hnode <- function(x) {
>     ## just prints
>     if (is.leaf(x))
>         print(x)
>     else
>         NULL
> }
> 
> 
> hnode <- function(x) {
>     ## doesn't work either
>     if (is.leaf(x))
>         strsplit(as.character(x), " ")[6]
>     else
>         NULL
> }
> 
> hnode <- function(x) {
>     ## prints; no storing
>     if (is.leaf(x))
>         print(x)
>     else
>         NULL
> }
> 
> hnode <- function(x) {
>     ## prints; no storing
>     if (is.leaf(x))
>         x
>     else
>         NULL
> }
> 
> 
> 
> 
> Thanks,
> 
> 
> R.
> 
> --
> Ramon Diaz-Uriarte
> Bioinformatics Unit
> Spanish National Cancer Centre (CNIO)
> http://ligarto.org/rdiaz
> 
> 
> **NOTA DE CONFIDENCIALIDAD** Este correo electr??nico, y en s...{{dropped}}
> 
> 
>