ファン クラスタのメイン ブランチに色を付ける方法を教えていただければ幸いです。
次の例を使用してください。
library(ape)
library(cluster)
data(mtcars)
plot(as.phylo(hclust(dist(mtcars))),type="fan")
ファン クラスタのメイン ブランチに色を付ける方法を教えていただければ幸いです。
次の例を使用してください。
library(ape)
library(cluster)
data(mtcars)
plot(as.phylo(hclust(dist(mtcars))),type="fan")
「メインブランチに色を付ける」とはどういう意味かをより具体的にする必要がありますが、これによりいくつかのアイデアが得られる場合があります。
phyl <-as.phylo(hclust(dist(mtcars)))
plot(phyl,type="fan", edge.col=c("black", "green")[1+(phyl$edge.length >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) ])
サンプルが属するクラスを示すためにメイン ブランチに色を付けたい場合は、R パッケージ sparcl の関数ColorDendrogramが役立つ場合があります (ここからダウンロードできます)。サンプルコードは次のとおりです。
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)
これにより、葉が2つのサンプルのどちらから来たかに応じて色付けされた樹形図が生成されます。