Graph of horizontal dendrogram with hanging leaves? (R)

I would like to create a dendrogram chart with horizontal labels, but the leaves will hang in their height, and not just go down to the edge of the chart.

Example:

par(mfrow = c(1,2)) hc <- hclust(dist(USArrests), "ave") plot(hc) # a plot with hanging branches plot(as.dendrogram(hc), horiz = TRUE) # a horizontal plot, but the branches are not hanging 

enter image description here

Any suggestion on how this can be programmed?

Thanks.

+4
source share
2 answers

You can change the value of hang in the as.dendrogram function.

 par(mfrow = c(1,2)) hc <- hclust(dist(USArrests), "ave") plot(hc) plot(as.dendrogram(hc, hang=0.02), horiz = TRUE) 
+2
source

For the record, I implemented the hang.dendrogram function (in the dendextend package) to allow the dendrogram to hang even after it was created (and not only during the transition from hclust to the dendrogram). Here's how to use it:

 install.packages("dendextend") library(dendextend) dend <- as.dendrogram(hclust(dist(USArrests), "ave")) par(mar = c(5,5,5,5)) plot(hang.dendrogram(dend), horiz = TRUE) 

enter image description here

+1
source

Source: https://habr.com/ru/post/1486018/


All Articles