ggdendrogram for a large number of nodes

623 Views Asked by At

I'm trying to plot a dendrogram with a large number of nodes using ggdendrogram and it's pretty slow (compared to dendextend for example):

set.seed(1)
mat <- matrix(rnorm(100*10),nrow=100,ncol=10)
dend <- as.dendrogram(hclust(dist(mat)))


require(ggdendro)
require(dendextend)
require(microbenchmark)
> microbenchmark(ggdendrogram(dend,rotate=T,labels=F,size=4,theme_dendro=F))
Unit: milliseconds
                                                                   expr      min       lq     mean  median       uq      max neval
 ggdendrogram(dend, rotate = T, labels = F, size = 4, theme_dendro = F) 394.3181 409.3591 431.0981 412.515 416.4568 1346.844   100

> microbenchmark(dend %>% plot(horiz = TRUE))
Unit: milliseconds
                        expr      min     lq     mean   median       uq      max neval
 dend %>% plot(horiz = TRUE) 138.7253 207.92 214.5278 208.8807 211.2602 640.0316   100

Is there any way to speed it up to make it comparable with dendextend's plot's speed?

Also, whether I specify rotate=T or

ggdendrogram(dend,rotate=F,labels=F,size=4,theme_dendro=F)+coord_flip()

I get the dendrogram pointing left: enter image description here

but I want it to point right instead. Any idea how to get that to work?

1

There are 1 best solutions below

2
On

At this stage, the dendextend package replaces ggdendro.

set.seed(1)
mat <- matrix(rnorm(100*10),nrow=100,ncol=10)
dend <- as.dendrogram(hclust(dist(mat)))
require(dendextend)
gg_dend <- as.ggdend(dend)
require(ggplot2)
ggplot(gg_dend, labels = F)+coord_flip()+ scale_y_reverse()

enter image description here