I have dendrogram
which I cut
the branches of for a given depth cutoff. I then want to plot it using ggplot
and limit the flipped y-axis:
set.seed(10)
mat <- matrix(rnorm(24*10,mean=1,sd=2),nrow=24,ncol=10)
dend <- as.dendrogram(hclust(dist(mat)))
I save the depth of the dendrogram for limiting the plot:
require(data.tree)
dend.depth <- as.Node(dend)$plotHeight
I cut the dendrogram
depth.cutoff <- 11
dend <- cut(dend,h=depth.cutoff)$upper
I plot the cut dendrogram
using dendextend
require(dendextend)
gg.dend <- as.ggdend(dend)
Plotting gg.dend
without limiting the y-axis produces branches that do not end at the same line:
require(ggplot2)
ggplot(gg.dend,labels=F)+scale_y_reverse()+coord_flip()
So I thought I can fix that by limiting the y-axis to be between dend.depth
and depth.cutoff
. But this doesn't come out well:
ggplot(gg.dend,labels=F)+scale_y_reverse(lim=c(dend.depth,tol.level))+coord_flip()