首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将colored_bars添加到设置了horiz=T的dendextend图中

如何将colored_bars添加到设置了horiz=T的dendextend图中
EN

Stack Overflow用户
提问于 2015-11-13 05:03:53
回答 1查看 366关注 0票数 3

我知道如何将彩色条形图添加到dendextend图中,但当我设置为horiz=T时,条形图绘制在错误的轴上。

dendextend简介中的示例显示了如何向绘图中添加彩色条形图:

代码语言:javascript
复制
dend15 <- c(1:5) %>% dist %>% hclust(method = "average") %>% as.dendrogram

is_odd <- ifelse(labels(dend15) %% 2, 2,3)
is_345 <- ifelse(labels(dend15) > 2, 3,4)
is_12 <- ifelse(labels(dend15) <= 2, 3,4)
k_3 <- cutree(dend15,k = 3, order_clusters_as_data = FALSE) 
# The FALSE above makes sure we get the clusters in the order of the
# dendrogram, and not in that of the original data. It is like:
# cutree(dend15, k = 3)[order.dendrogram(dend15)]
the_bars <- cbind(is_odd, is_345, is_12, k_3)
the_bars[the_bars==2] <- 8

dend15 %>% plot(horiz=F)
colored_bars(colors = the_bars, dend = dend15)

当我执行上面的代码时,我看到了这个图:

colored_bars plot good example

但是,当我键入

代码语言:javascript
复制
dend15 %>% plot(horiz=T) 
colored_bars(colors = the_bars, dend = dend15)

这是我所看到的:

colored_bars plot bad example

是否可以将彩色条移动到树的叶节点旁边的轴上?

EN

回答 1

Stack Overflow用户

发布于 2019-03-13 00:32:42

也许这段代码(取自here)可以帮助你:

代码语言:javascript
复制
par(mar = c(4,1,1,12))
plot(dend15, horiz = TRUE)
colored_bars(dend15, colors = the_bars, horiz = TRUE)

祝好运!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33681321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档