ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

ggdensitree + revts

Open thijsjanzen opened this issue 4 years ago • 2 comments
trafficstars

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)

thijsjanzen avatar Sep 22 '21 13:09 thijsjanzen

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

brj1 avatar Sep 26 '21 21:09 brj1

Works like a charm! Also, works for all densitrees

thijsjanzen avatar Sep 27 '21 09:09 thijsjanzen