2011-12-06 5 views

答えて

5

ノードを横断する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) 

enter image description here

+0

ああ、戻って私を取ります(http://stackoverflow.com/questions/4720307/change-dendrogram- leafs-in-r)。いつこれがドキュメントに入ったのですか? –

関連する問題