문제

I would like to create a dendrogram plot with horizontal labels, but having the leaves hang according to their height, instead of just drop to the edge of the plot.

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.

도움이 되었습니까?

해결책

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)

다른 팁

For the record, I've implemented a hang.dendrogram function (in the dendextend package), to allow hanging a dendrogram also after is was created (and not only during the changing from hclust to a dendrogram). Here is 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top