>>>>> "Timo" == Timo Becker <timo.becker at
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