I have generated a dendrogram using plot() function and used hclust() for hierarchical clustering. I am looking to generate a scree plot for the same. Any suggestions?
It's a little late, but I have an answer.
# creating a dissimilarity matrix
res.dist <- dist(USArrests, method = "euclidean")
# creating an object of class "hclust"
res.hc <- hclust(d = res.dist, method = "ward.D2")
As can be found in the documentation to hclust, it is a list of values. You can inspect them by using
View(res.hc)
Now, the variable height has exactly what is needed for a scree plot. The following code generates a scree plot:
> ggplot(res.hc$height %>%
+ as.tibble() %>%
+ add_column(groups = length(res.hc$height):1) %>%
+ rename(height=value),
+ aes(x=groups, y=height)) +
+ geom_point() +
+ geom_line()
Basically, what you do is plot the height for a number of groups. (It might not be very elegant, I'd be delighted to hear shorter versions to generate the same outcome).
My outcome is:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With