【问题标题】:How can I colour the nodes of a dendrogram as separate rows in R如何将树状图的节点着色为 R 中的单独行
【发布时间】:2016-12-15 11:36:30
【问题描述】:

我想为树状图底部的树状图节点着色 - 但在单独的行中 下面链接中的最后一个树状图将节点显示为彩色 - 但是当它是一个大数据集时,一条线变得非常模糊 Label and color leaf dendrogram in r 那么每个颜色组可以有单独的行吗?

【问题讨论】:

    标签: hierarchical-clustering dendrogram dendextend


    【解决方案1】:

    是的。您想使用 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-11
      • 2015-09-16
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      • 1970-01-01
      相关资源
      最近更新 更多