[R] Colouring hclust() trees
Martin Keller-Ressel
martin at ist.org
Tue May 11 13:47:51 CEST 2004
How about this:
"hc" is your hclust object,"colv" the color vector ordered like the
original data
and "height" the height of the color bar as fraction of dendrogram height.
colorplot.hclust <- function(hc,colv,height=.05) {
plot(hc,lab=FALSE,hang=0)
stopifnot(length(hc$order) == length(colv))
xy.mat <- list(x=1:length(colv),y=c(-max(hc$height)*height,0))
image(xy.mat,z=matrix(colv[hc$order],ncol=1),add=TRUE)
}
## Example:
data(iris)
hc1 <- hclust(dist(scale(iris[,1:4])),method="ward")
colorplot.hclust(hc1,as.numeric(iris[,5]))
hth,
Martin Keller-Ressel
--
More information about the R-help
mailing list