[英]Cluster labels are cut off on horizontal hclust dendrogram
I used hclust
and as.dendogram
to make a dendrogram, but when I rotate it to a horizontal orientation, the model names are cut off. 我使用hclust
和as.dendogram
制作了树状图,但是当我将其旋转到水平方向时,将切断模型名称。 How can I make sure that the plot shows the entire model names? 我如何确保该图显示整个模型名称?
You need to play with the margin. 您需要保证金。 Here is an example (it also uses dendextend to give extra control over the color and shape of the dendrogram) 这是一个示例(它还使用dendextend对树状图的颜色和形状进行额外控制)
library(dendextend)
library(dplyr)
small_mtcars <- head(mtcars) %>% select(mpg, cyl, disp)
small_mtcars
d1 = small_mtcars %>% dist() %>% hclust(method = "average") %>% as.dendrogram()
library(colorspace)
some_colors <- rainbow_hcl(nrow(small_mtcars))
d1_col <- some_colors[order.dendrogram(d1)]
# some colors for fun
d1 <- d1 %>%
set("labels_cex",1.2) %>%
set("labels_colors", value= d1_col) %>%
set("leaves_pch", 19) %>%
set("leaves_cex", 2) %>%
set("leaves_col", value= d1_col)
par(mfrow = c(1,2))
par(mar = c(2,2,2,2))
d1 %>%
plot(main="d1 (bad margins)", horiz = TRUE)
par(mar = c(2,2,2,10))
d1 %>%
set("labels_cex",1.2) %>%
plot(main="d1 (good margins)", horiz = TRUE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.