既存の列を使用してデンドログラムの枝に色を付ける質問から、デンドログラムの葉の近くの枝に色を付けることができます。コード:
x<-1:100
dim(x)<-c(10,10)
set.seed(1)
groups<-c("red","red", "red", "red", "blue", "blue", "blue","blue", "red", "blue")
x.clust<-as.dendrogram(hclust(dist(x)))
x.clust.dend <- x.clust
labels_colors(x.clust.dend) <- groups
x.clust.dend <- assign_values_to_leaves_edgePar(x.clust.dend, value = groups, edgePar = "col") # add the colors.
x.clust.dend <- assign_values_to_leaves_edgePar(x.clust.dend, value = 3, edgePar = "lwd") # make the lines thick
plot(x.clust.dend)
に示すように樹状図を生成します。
ただし、現在のブランチのすべての葉が同じラベルになるまで、ルートに向かってブランチに色を付けたいと考えています。1 つでも不一致があった場合でも、既定の色である黒に切り替えます。結果のデンドログラムを次のようにしたい
私が欲しいのはcolor_branches
likeを使うのと少し違う
x.clust.dend <-color_branches(x.clust.dend,k=3)
一部の外部ラベルに基づくのではなく、独自のクラスターに基づいて色付けされるためです。