YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/contribution-tree-data/
839 stars 172 forks source link

ggdensitree + revts #437

Open thijsjanzen opened 3 years ago

thijsjanzen commented 3 years ago

I would like to make a plot as hinted here: https://github.com/YuLab-SMU/ggtree/issues/87 e.g. a densitree with a timescale with 0 at the tips, and -crown_age at the root.

However, the following code does not work as expected, and only reverts one of the two tree plots.

trees <- list()
trees[[1]] <- rtree(n = 10)
trees[[2]] <- rtree(n = 10)
class(trees) <- "multiPhylo"
p <- ggdensitree(trees) + theme_tree2()
p2 <- revts(p)
multiplot(p, p2, ncol=2)
brj1 commented 3 years ago

I have built a workaround for this in 5a70208dbea02567bd11eec7fe2e99ef369b3ef9. ggdensitree will set the maximum tip date to 0 when align.tips = TRUE (the default). So,

trees <- list()
trees[[1]] <- rtree(n = 10)
trees[[2]] <- rtree(n = 10)
class(trees) <- "multiPhylo"
p <- ggdensitree(trees) + theme_tree2()
p

will produce the plot you want, with no revts required.

ggtree2

thijsjanzen commented 3 years ago

Works like a charm! Also, works for all densitrees