3

我了解如何将彩色条添加到 deendextend 图中,但是当我设置 horiz=T 时,条被绘制在错误的轴上。

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

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)

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

coloured_bars 绘制很好的例子

但是,当我输入

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

这就是我所看到的:

coloured_bars 情节不好的例子

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

4

1 回答 1

1

也许这段代码(取自此处)可以帮助您:

par(mar = c(4,1,1,12))
plot(dend15, horiz = TRUE)
colored_bars(dend15, colors = the_bars, horiz = TRUE)

祝你好运!

于 2019-03-12T16:32:41.830 回答