I am trying to estimate a cluster dendrogram in R for a structural topic model I produced with 98 topics.
I first ran the following which worked well:
res.hc <- eclust(scale(out_corr$cor), "hclust", nboot = 500)
I then attempting to visualize the dendrogram using the following syntax:
fviz_dend(res.hc, rect = TRUE)
Here, I received the following error: Error in .rect_dendrogram(dend, k = k, palette = rect_border, rect_fill = rect_fill, : k must be between 2 and 97
Is this because the number of topics in my model is 98? If so, is there a way to still visualize the dendrogram without reducing my topics to 97?
Thank you!
The following steps helped to resolve the issue:
res.hc <- eclust(scale(out_corr$cor), "hclust", nboot = 500)
install.packages("dendextend")
library(dendextend)
install.packages("dplyr")
library(dplyr)
dend<-as.dendrogram(res.hc)
par(mar=c(1,1,1,7))
dend %>%
set("labels_col", value = c("skyblue", "red", "grey", "blue"), k=4) %>%
set("branches_k_color", value = c("skyblue", "red", "grey", "blue"), k = 4) %>%
plot(horiz=FALSE, axes=FALSE)
abline(v = 350, lty = 2)