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
I am tryingt to answer this question
(b) Cut the dendrogram at a height that results in three distinct clusters. 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
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.