I am trying to draw a dendrogram from the hclust
function output. I hope the dendrogram is horizontally arranged instead of the default, which can be obtain by
Using dendrapply
you can customize your dendro as you like.
colLab <- function(n) {
if(is.leaf(n)) {
a <- attributes(n)
attr(n, "label") <- substr(a$label,1,2) # change the node label
attr(n, "nodePar") <- c(a$nodePar, lab.col = 'red') # change the node color
}
n
}
require(graphics)
hc <- hclust(dist(USArrests), "ave")
clusDendro <- as.dendrogram(hc)
clusDendro <- dendrapply(clusDendro, colLab)
op <- par(mar = par("mar") + c(0,0,0,2))
plot(clusDendro,horiz=T)