R树形图中叶子之间的较大字体和间距

时间:2014-11-17 04:10:01

标签: r tree dendrogram dendextend

我在R中有一个树状图,我只能做对了。

我会告诉您问题所在,请查看:http://img.photobucket.com/albums/v699/rica01/Rplot-1.png

如何在树叶上制作标签,更大,间距更大?

感谢。

-Ricardo

1 个答案:

答案 0 :(得分:3)

解决方案:使用set函数以及dendextend包中的“labels_cex”参数。

# 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

(请注意,目前尚未实现更改标签之间的间距)

有关该软件包的更多详细信息,您可以查看at its vignette