[英]cutting a dendogram in R USArrests dataset does not return a proper dendogram
I have been looking online for tutorial but the result is not correct我一直在网上找教程,但结果不正确
d <- dist(USArrests, method = "euclidean") # distance matrix
usarrests_hi_cluster <- hclust(d, method="complete")
plot(usarrests_hi_cluster)
This works fine and I get the whole dendogram这很好用,我得到了整个树状图
but when I do the following to prune at certain height但是当我执行以下操作以在特定高度修剪时
my_dend<-cutree(usarrests_hi_cluster, h = 150)
print(my_dend)
only get a list of the states with a number只获取带有数字的州列表
Alabama Alaska Arizona Arkansas
1 1 1 2
California Colorado Connecticut Delaware
1 2 3 1
Florida Georgia Hawaii Idaho
1 2 3 3
Illinois Indiana Iowa Kansas
1 3 3 3
Kentucky Louisiana Maine Maryland
3 1 3 1
I want to cut the dendogram at a certain height to get 3 clusters and plot it我想在某个高度切割树状图以获得 3 个簇和 plot 它
I am tryingt to answer this question我试图回答这个问题
(b) Cut the dendrogram at a height that results in three distinct clusters. (b) 在产生三个不同簇的高度处切割树状图。 Which states belong to which clusters?哪些州属于哪些集群?
See this question/answer for the same question but plotting the top of the tree: Plotting hclust only to the cut clusters, not every leaf请参阅此问题/答案以获得相同的问题,但绘制树的顶部: 仅将 hclust 绘制到切割的簇,而不是每个叶子
What you are looking for are is plotting the lower branches.您正在寻找的是绘制较低的分支。 The branch levels is stored as a list in the "$lower" variable of the data structure.分支级别作为列表存储在数据结构的“$lower”变量中。
hc <- hclust(dist(USArrests))
#cut tree
dend2 <- cut(dend1, h = 150)
#cycle through the lower list and plot
lapply(dend2$lower, function(x){plot(x)})
To answer part (b): The output of print(my_dend)
is showing which branch each state belongs to.回答 (b) 部分: print(my_dend)
的 output 显示每个 state 属于哪个分支。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.