Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

larger font and spacing between leaves in R dendrogram

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

like image 969
rica01 Avatar asked Sep 29 '22 09:09

rica01


1 Answers

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.

like image 149
Tal Galili Avatar answered Oct 02 '22 16:10

Tal Galili