我想在树状图的底部给树状图的节点着色--但是在下面的链接中,最后一个树状图在单独的行中显示节点是彩色的-然而,当它是一个大数据集时,一条线变得非常污浊的Label and color leaf dendrogram in r,所以每个有色组都有单独的行是可能的吗?
发布于 2016-12-24 10:28:42
是。您希望使用dendextend包中的函数colored_bars
。请参见以下示例(来自dendextend vignette)
library(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
colored_bars(colors = the_bars, dend = dend15)
https://stackoverflow.com/questions/41163213
复制相似问题