改变树状图的叶子 [英] Change Dendrogram leaves

查看:101
本文介绍了改变树状图的叶子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改根据hclust对象的图生成的树状图中的叶子属性.最低限度,我想更改颜色,但是您能提供的任何帮助将不胜感激.

I want to modify the properties of the leaves in a dendrogram produced from plot of an hclust object. Minimally, I want to change the colors, but any help you can provide will be appreciated.

我确实尝试过搜索答案,但是我看到的每个解决方案似乎都比我想像的要难得多.

I did try to google the answer, but but every solution that I saw seemed alot harder than what I would have guessed.

推荐答案

前一段时间,Joris Meys很好地向我提供了此代码片段,该代码片段可改变叶子的颜色.对其进行修改以反映您的属性.

A while ago, Joris Meys kindly provided me with this snippet of code that changes the color of leaves. Modify it to reflect your attributes.

clusDendro <- as.dendrogram(Clustering)
labelColors <- c("red", "blue", "darkgreen", "darkgrey", "purple")

## function to get colorlabels
colLab <- function(n) {
   if(is.leaf(n)) {
       a <- attributes(n)
       # clusMember - a vector designating leaf grouping
       # labelColors - a vector of colors for the above grouping
       labCol <- labelColors[clusMember[which(names(clusMember) == a$label)]]
       attr(n, "nodePar") <- c(a$nodePar, lab.col = labCol)
   }
   n
}

## Graph
clusDendro <- dendrapply(clusDendro, colLab)
op <- par(mar = par("mar") + c(0,0,0,2))
plot(clusDendro,
     main = "Major title",
     horiz = T, type = "triangle", center = T)

par(op)

这篇关于改变树状图的叶子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆