[英]Plot horizontal dendrogram with hanging leaves? (R)
我想创建一个带有水平标签的树形图,但是叶子根据它们的高度悬挂,而不是仅仅下降到绘图的边缘。
例:
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
关于如何编程的任何建议?
谢谢。
您可以在as.dendrogram
函数中更改hang
的值。
par(mfrow = c(1,2))
hc <- hclust(dist(USArrests), "ave")
plot(hc)
plot(as.dendrogram(hc, hang=0.02), horiz = TRUE)
为了记录,我已经实现了一个hang.dendrogram
函数(在dendextend包中),允许在创建之后挂起树形图(并且不仅在从hclust更改为树形图期间)。 以下是如何使用它:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.