larger font and spacing between leaves in R dendrogram

3.4k views Asked by At

I have a dendrogram in R that I just can't get it right.

I'll show you what the problem is, please check this: http://img.photobucket.com/albums/v699/rica01/Rplot-1.png

How can I make the labels on the leaves, bigger and more spaced between them?

Thanks.

-Ricardo

1

There are 1 answers

0
Tal Galili On

Solution: use the set function, with the "labels_cex" parameter from the dendextend package.

# install.packages("dendextend")
library(dendextend)

dend <- as.dendrogram(hclust(dist(USArrests[1:5,])))
# Like: 
# dend <- USArrests[1:5,] %>% dist %>% hclust %>% as.dendrogram

# By default, the dend has no text size to it (showing only the first leaf)
get_leaves_nodePar(dend)[[1]]
par(mfrow = c(1,2), mar = c(10,4,4,2))
plot(dend, main = "Original dend")

# let's increase the size of the labels:
dend <- set(dend, "labels_cex", 2)
# Now each state has a larger label
get_leaves_nodePar(dend)[[1]]
plot(dend, main = "A larger font for labels")

enter image description here

(note that changing the spacing between the labels is currently not implemented)

For more details on the package, you can have a look at its vignette.