Aligning a tree structure with an alluvial plot using ggtreeExtra

17 Views Asked by At

I am trying to align a tree structure I made with ggtree to an alluvial plot I made with ggalluvial. Here is a simple example data and the code I used:

library(ggtreeExtra)
library(ggtree)
library(ggalluvial)

data <- data.frame(v1 = c("t1","t2","t3","t1","t1","t2"), 
               v2 = c("v1","v2","v3","v2","v3","v3"), 
               n = c(1,1,1,2,3,1))



tr <- rtree(3)
p_tree <- ggtree(tr)+geom_tiplab(align=TRUE)

p_tree  + geom_fruit(data = data, geom = geom_alluvium, 
                     mapping = aes(y = n, axis1 = v1,
                                   axis2 = v2, fill = v1))

But I get the following error:

"Error in $<-.data.frame(*tmp*, "xtmp", value = 0) : replacement has 1 row, data has 0"

Any idea what is going wrong?

I tried to have the same order in the tree and the ggalluvial data, but it's still not working.

0

There are 0 best solutions below