How should I go about vizualizing dendrograms easily?

41 views Asked by At

I am using hierarchical clustering to construct a dendrogram for sites with similar fish densities. I seem to reach a limit where I want to draw a dendrogram with 14 clusters but fviz doesn't want to draw less than 15 clusters, which is a rather annoying problem. I also want to display a single name for each cluster but am having trouble in doing so, as I can't find a good way to do so except writing something like:

xlab = "1                2                    3                        4                  5",

I got recommended to use fviz_dend but I am open to new suggestions.

I use hclus to generate the hierachial cluster then use fviz_dend to draw the dendrogram. As I said I would want k = 14 but there seems to be a lower limit due to maybe the size of my dataset(?), but just by looking at the dendrogram I don't see a problem by drawing 14 clusters instead of 15 Dendrogram with 15 clusters.

enter image description here

The error I'm getting when trying anything below 15 clusters is

Error in data.frame(xmin = unlist(xleft), ymin = unlist(ybottom), xmax = unlist(xright),  : 
  arguments imply differing number of rows: 14, 0

And this is the code I'm using to generate the hclust and drawing the dendrogram

spe.ch.complete <- hclust(spe.ch, method = "complete")

fviz_dend(x = spe.ch.complete, cex = 0.7, lwd = 0.7, k = 15,
          show_labels = F,
          rect = T,
          k_colors = c("red", "darkgreen", "blue", "purple"),
          rect_border = c("red", "green", "cornflowerblue", "magenta"),
          rect_fill = T)

So my main problems are drawing 14 clusters and I want a single label for each cluster, to name the cluster.

0

There are 0 answers