【问题标题】:Highlight and color a specific node on a dendrogram plotted on a heatmap在热图上绘制的树状图上突出显示特定节点并为其着色
【发布时间】:2011-12-06 15:18:11
【问题描述】:

我在热图上绘制了一个树状图。 如何只选择一个节点和相应的叶子并为其着色? 提前致谢!

埃莉奥诺拉

【问题讨论】:

    标签: r


    【解决方案1】:

    利用dendrapply 遍历节点。 ?dendrapply 中有一个工作示例,说明了如何设置节点的颜色:

    require(graphics)
    
    ## a smallish simple dendrogram
    dhc <- as.dendrogram(hc <- hclust(dist(USArrests), "ave"))
    (dhc21 <- dhc[[2]][[1]])
    
    ## too simple:
    dendrapply(dhc21, function(n) utils::str(attributes(n)))
    
    ## toy example to set colored leaf labels :
    local({
      colLab <<- function(n) {
          if(is.leaf(n)) {
            a <- attributes(n)
            i <<- i+1
            attr(n, "nodePar") <-
                c(a$nodePar, list(lab.col = mycols[i], lab.font= i%%3))
          }
          n
      }
      mycols <- grDevices::rainbow(attr(dhc21,"members"))
      i <- 0
     })
    dL <- dendrapply(dhc21, colLab)
    op <- par(mfrow=2:1)
     plot(dhc21)
     plot(dL) ## --> colored labels!
    par(op)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 2021-01-06
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多