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 with align.tips=TRUE sets max x to 0 #439

Closed brj1 closed 3 years ago

brj1 commented 3 years ago

Hi Dr. Yu,

In response to #437, I thought that it might be better for ggdensitree to set the maximum x value to 0 when you align tips instead of the default value which is the height of the tallest tree. With this change

ggdensitree(trees) + theme_tree2()

would appear as if you ran revts on the plot. I think this works better because many of times that people will want to use ggdensitree, they will want to indicate time in the past. And if they want to indicate calendar dates it is easier to work from the tip dates than from a root which may have an arbitrary date.

As an aside, I think that the revts function might need to be reworked, since it doesn't really follow the ggplot philosophy. Maybe you could turn it into a scale?

GuangchuangYu commented 3 years ago

it seems there is no change in the https://github.com/YuLab-SMU/ggtree/issues/437 plot.

brj1 commented 3 years ago

My PR does not fix revts for ggdensitree plots. Instead it makes the the x-axis, 0, at the rightmost maximum tip, essentially incorpating revts into ggdensitree. It only does this when align.tips = TRUE. If align.tips = FALSE, then x=0 is at the root.

Compare the following code on 5d2d10d4a5b99404c85fd4bb97e2f6948e13c64b and 5ad1c432aa554dd2e2b853d3eaa76366b16b3b8b

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

5d2d10d4a5b99404c85fd4bb97e2f6948e13c64b

ggtree1

5ad1c432aa554dd2e2b853d3eaa76366b16b3b8

ggtree2

EDIT: Sorry I forgot to set the same seed for the random trees, in the two runs. But the important thing is to look at the axes.