[英]dendextend: Increase font size of dendogram nodes in groupLabels?
[英]groupLabels not shown when using dendextend colour_branches
我要實現的工作流程是:
dm <- dist(data)
dend <- hclust(dm)
k <- stats::cutree(dend, k = 10)
data$clusters <- k
plot(hclust, colorBranchees = k) #???? What I can use here.
所以我使用cutree
output搜索了彩色樹狀圖分支。 我發現的只是dendextend
。
問題是我無法使用dendextend
實施工作流程。
這就是我想出的,但我現在想顯示clusterLabels
library(dendextend)
hc <- hclust(dist(USArrests))
dend <- as.dendrogram(hc)
kcl <- dendextend::cutree(dend, k = 4)
dend1 <- color_branches(dend, clusters = kcl[order.dendrogram(dend)], groupLabels = TRUE)%>% set("labels_cex", 1)
plot(dend1, main = "Dendrogram dist JK")
此外,嘗試類似groupLabels = 1:4
也無濟於事。
使用參數k
(o 簇的數量)指定 groupLable 確實有效。 但不幸的是,標簽與dendextend自己的cutree方法生成的標簽不同。
請注意,此處集群 4 有 2 個成員。
> table(kcl)
kcl
1 2 3 4
14 14 20 2
這篇文章建議使用dendextend::cutree(dend,k = nrCluster, order_clusters_as_data = FALSE)
r dendrogram - groupLabels 與真實標簽不匹配(dendextend 包)
但是后來我不能使用dendextend::cutree
的 output 對數據進行分組(因為排序不匹配。
我很樂意在 R 中使用不同的樹狀圖繪圖庫,但到目前為止,我的 Web 搜索“通過 cutree 輸出着色樹狀圖分支”指向 Dendextend ZEFE90A8E603A67C840D8Z8D。
很抱歉,但我不確定我是否完全理解你的問題。
您似乎想在 curtree 的 output 和原始數據之間對齊。 如果是這種情況,那么您需要使用dendextend::cutree(dend,k = nrCluster, order_clusters_as_data = TRUE)
例如:
require(dendextend)
d1 <- USArrests[1:10,]
hc <- hclust(dist(d1))
dend <- as.dendrogram(hc)
k <- dendextend::cutree(dend, k = 3, order_clusters_as_data = TRUE)
d2 <- cbind(d1, k)
plot(color_branches(dend, 3))
d2
# an easier way to see the clusters is by ordering the rows of the data based on the order of the dendrogram
d2[order.dendrogram(dend),]
plot 很好:
並且集群正確映射到數據(見輸出)
> require(dendextend)
> d1 <- USArrests[1:10,]
> hc <- hclust(dist(d1))
> dend <- as.dendrogram(hc)
> k <- dendextend::cutree(dend, k = 3, order_clusters_as_data = TRUE)
> d2 <- cbind(d1, k)
> plot(color_branches(dend, 3))
> d2
Murder Assault UrbanPop Rape k
Alabama 13.2 236 58 21.2 1
Alaska 10.0 263 48 44.5 1
Arizona 8.1 294 80 31.0 2
Arkansas 8.8 190 50 19.5 1
California 9.0 276 91 40.6 2
Colorado 7.9 204 78 38.7 1
Connecticut 3.3 110 77 11.1 3
Delaware 5.9 238 72 15.8 1
Florida 15.4 335 80 31.9 2
Georgia 17.4 211 60 25.8 1
> # an easier way to see the clusters is by ordering the rows of the data based on the order of the dendrogram
> d2[order.dendrogram(dend),]
Murder Assault UrbanPop Rape k
Connecticut 3.3 110 77 11.1 3
Florida 15.4 335 80 31.9 2
Arizona 8.1 294 80 31.0 2
California 9.0 276 91 40.6 2
Arkansas 8.8 190 50 19.5 1
Colorado 7.9 204 78 38.7 1
Georgia 17.4 211 60 25.8 1
Alaska 10.0 263 48 44.5 1
Alabama 13.2 236 58 21.2 1
Delaware 5.9 238 72 15.8 1
如果這回答了您的問題或者您在此處有后續問題,請 LMK。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.