[R] x/y coordinates of dendrogram branches
Timo Becker
timo.becker at oeaw.ac.at
Wed Nov 2 14:51:02 CET 2005
Dear R-users,
I need some help concerning the plotting of dendrograms for hierarchical
agglomerative clustering.
The agglomeration niveau of each step should be displayed at the
branches of the dendrogram.
For this I need the x/y coordinates of the branch-agglomerations of the
dendrogram.
The y-values are known (the heights of the agglomeration), but how can I
get the x-values?
> mydata <- c(1,2,3,4,5)
> hc <- hclust(dist(mydata), method="average")
> hc$height # these are the y-coordinates
[1] 1.0 1.0 1.5 2.5
I experimented with the dendrogram object because it gives the midpoints:
> dend <- as.dendrogram(hc)
> attributes(dend[[1]])$midpoint
[1] 0.5
Perhaps I could loop over all possible branches and get the midpoints if
I knew how to convert them to x-values.
The manual says that midpoint is the "numeric horizontal distance of the
node from the left border (the leftmost leaf) of the
branch (unit 1 between all leaves)."
But how do I know which one is the leftmost leaf and what is its
horizontal value?
Thanks in advance,
Timo
More information about the R-help
mailing list