Re: [R] creating dendrogram from cluster hierarchy

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue 28 Feb 2006 - 21:19:47 EST

>>>>> "Timo" == Timo Becker <timo.becker@oeaw.ac.at>
>>>>> on Tue, 28 Feb 2006 11:01:26 +0100 writes:

    Timo> Dear R users, I have created data for hierarchical
    Timo> agglomerative cluster analysis which consist of the
    Timo> merging pairs and the agglomeration heights, e.g.
    Timo> something like

    Timo> my.merge <- matrix(c(-1,-2,-3,1), ncol=2, byrow=TRUE)     Timo> my.height <- c(0.5, 1)

    Timo> I'd like to plot a corresponding dendrogram but I
    Timo> don't know how to convert my data to achieve this.  Is
    Timo> it possible to create a dendrogram object from a
    Timo> cluster hierarchy?

Yes, it is possible. R does it already with the as.dendrogram() method for objects of class "hclust".

But I assume you'd also like to know *how* you can do it... ;-)

I'd strongly recommend to take the example of hclust() and have your function return an object ``like'' the one hclust() returns. Then, as.dendrogram( <your object> ) will work.

You have to decide for yourself if your function should return an object of class "hclust" (which is partly described by ?hclust ), and you use as.dendrogram[.hclust]() directly, or rather your function returns a class "hclustTimo" and you write your own as.dendrogram.hclustTimo() method.

I'd recommend looking at and using the R's source code, e.g., from https://svn.R-project.org/R/trunk/src/library/stats/R/hclust.R and https://svn.R-project.org/R/trunk/src/library/stats/R/dendrogram.R

Regards,
Martin Maechler, ETH Zurich



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Feb 28 21:30:21 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:47 EST