在热图上绘制的树形图上突出显示并着色特定节点

Elb*_*Elb 4 r

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

爱莲

And*_*rie 6

利用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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述