对于给定的深度截止,我有dendrogram
它cut
的分支。然后我想使用它来绘制它ggplot
并限制翻转的 y 轴:
set.seed(10)
mat <- matrix(rnorm(24*10,mean=1,sd=2),nrow=24,ncol=10)
dend <- as.dendrogram(hclust(dist(mat)))
我保存树状图的深度以限制绘图:
require(data.tree)
dend.depth <- as.Node(dend)$plotHeight
我剪了dendrogram
depth.cutoff <- 11
dend <- cut(dend,h=depth.cutoff)$upper
我dendrogram
使用dendextend
require(dendextend)
gg.dend <- as.ggdend(dend)
在不限制 y 轴的情况下绘图gg.dend
会产生不在同一行结束的分支:
require(ggplot2)
ggplot(gg.dend,labels=F)+scale_y_reverse()+coord_flip()
所以我想我可以通过将 y 轴限制在dend.depth
和之间来解决这个问题depth.cutoff
。但这并不好:
ggplot(gg.dend,labels=F)+scale_y_reverse(lim=c(dend.depth,tol.level))+coord_flip()