r - 集群标签在水平 hclust dendrogram 上被切断
问题描述
我用hclust
andas.dendogram
来制作树状图,但是当我将它旋转到水平方向时,模型名称会被截断。如何确保绘图显示整个模型名称?
解决方案
你需要发挥边际。这是一个示例(它还使用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)
推荐阅读
- rest - 我可以使用分块编码使用 Java REST API 下载巨大的静态文件吗?
- c# - 从 HangFire ContinueJobWith 方法中的 lambda 表达式获取方法输出
- python - docker-compose up 卡在附加到
- angular - 使用 Ionic 中的键值过滤结果 subscribe()
- python - Python discord bot 检查所有用户的特定角色,该角色也具有特定角色
- c++ - 从 jpeg 数据创建位图
- php - 在php中使用strtotime格式获取多少天
- sql - SQL中的1对多关系
- javascript - 嵌套对象 Axios Post
- python - 如何在 django 中使用仿函数而不是函数?