My R package TBEST has a function that can add two color annotations to a hclust object. For your convenience, I am pasting codes below, so you can use them independent of any packages.
hc2axes<-function (x) {
A <- x$merge
n <- nrow(A) + 1
x.axis <- c()
y.axis <- x$height
x.tmp <- rep(0, 2)
zz <- match(1:length(x$order), x$order)
for (i in 1:(n - 1)) {
ai <- A[i, 1]
if (ai < 0)
x.tmp[1] <- zz[-ai]
else x.tmp[1] <- x.axis[ai]
ai <- A[i, 2]
if (ai < 0)
x.tmp[2] <- zz[-ai]
else x.tmp[2] <- x.axis[ai]
x.axis[i] <- mean(x.tmp)
}
return(data.frame(x.axis = x.axis, y.axis = y.axis))
}
plot_height<-function (hc, height, col = c(2, 3), print.num = TRUE, float = 0.01, cex = NULL, font = NULL)
{
axes <- hc2axes(hc)
usr <- par()$usr
wid <- usr[4] - usr[3]
bp <- as.character(round(height,2))
rn <- as.character(1:length(height))
bp[length(bp)] <- "height"
rn[length(rn)] <- "edge #"
a <- text(x = axes[, 1], y = axes[, 2] + float * wid, bp,
col = col[1], pos = 2, offset = 0.3, cex = cex, font = font)
if (print.num) {
a <- text(x = axes[, 1], y = axes[, 2], rn, col = col[2],
pos = 4, offset = 0.3, cex = cex, font = font)
}
}
Once you paste these two functions, add one line to plot your dendrogram,
plot(clusters,labels=points$ID);
cluster_height(clusters,height=clusters$height,print.num=F)
You can also plot the branch numbers by setting print.num=T
