简体   繁体   English

如何在簇树形图中对分支进行着色?

[英]How to color branches in cluster dendrogram?

I will appreciate it so much if anyone of you show me how to color the main branches on the Fan clusters. 如果你们中的任何人向我展示如何为Fan群集上的主要分支着色,我将非常感激。

Please use the following example: 请使用以下示例:

library(ape)
library(cluster) 
data(mtcars)
plot(as.phylo(hclust(dist(mtcars))),type="fan")

You will need to be more specific about what you mean by "color the main branches" but this may give you some ideas: 您需要通过“为主要分支着色”更具体地说明您的意思,但这可能会给您一些想法:

 phyl <-as.phylo(hclust(dist(mtcars))) 
 plot(phyl,type="fan", edge.col=c("black", "green")[1+(phyl$edge.length >40) ])

The odd numbered edges are the radial arms in a fan plot so this mildly ugly (or perhaps devilishly clever?) hack colors only the arms with length greater than 40: 奇数边缘是扇形图中的径向臂,所以这个稍微丑陋(或者可能是非常聪明的?)黑客的颜色只有长度大于40的臂:

phyl <-as.phylo(hclust(dist(mtcars)))
plot(phyl,type="fan", edge.col=c("black", "black", "green")[
                                        c(TRUE, FALSE) + 1 + (phyl$edge.length >40) ])

If you want to color the main branches to indicate which class that sample belongs to, then you might find the function ColorDendrogram in the R package sparcl useful (can be downloaded from here ). 如果你要的颜色主要分支,表明样品属于哪一类,那么你可能会发现在R包SPARCL有用的(可以从下载的功能ColorDendrogram 这里 )。 Here's some sample code: 这是一些示例代码:

library(sparcl)

# Create a fake two sample dataset
set.seed(1)
x <- matrix(rnorm(100*20),ncol=20)
y <- c(rep(1,50),rep(2,50))
x[y==1,] <- x[y==1,]+2

# Perform hierarchical clustering
hc <- hclust(dist(x),method="complete")

# Plot
ColorDendrogram(hc,y=y,main="My Simulated Data",branchlength=3)

This will generate a dendrogram where the leaves are colored according to which of the two samples they came from. 这将生成树状图,其中叶子根据它们来自哪两个样品着色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM