larger font and spacing between leaves in R dendrogram

∥☆過路亽.° 提交于 2019-12-07 06:51:57

问题


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:


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")

(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.



来源:https://stackoverflow.com/questions/26965390/larger-font-and-spacing-between-leaves-in-r-dendrogram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!