YuLab-SMU / ggtree

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

Multiple trees are plotted by shape instead of label #221

Open richelbilderbeek opened 5 years ago

richelbilderbeek commented 5 years ago

Prerequisites

Describe you issue

Hi @GuangchuangYu, thanks for ggtree! There is some behavior that I think may be incorrect. I hope you can fix that, or my misunderstanding :+1:. Cheers, @richelbilderbeek

Here is the reprex:

library(ape)
library(ggplot2)

# Here I create two trees. In one tree, taxon 'C' is the outlier. In the other tree, taxon 'B' is the outlier
tree_1 <- ape::read.tree(text = "((A:2,B:2):1, C:3);")
tree_2 <- ape::read.tree(text = "((A:1,C:1):2, B:3);")

# Show it in a picture:
plot(tree_1)
plot(tree_2)

tree_1

tree_2

# Combine the trees
trees <- c(tree_1, tree_2)

# Show them overlapping
ggtree::ggtree(trees) + ggtree::geom_tiplab()

The tree created by ggtree shows that C is the outlier in both cases:

tree_created

This is a plot I would have expected, in which B and C are outliers each once:

tree_expected

Ask in right place

GuangchuangYu commented 5 years ago

Yes, it is a bug. This bug was caused by supporting phyloseq object, we need to allow node duplications, see https://github.com/GuangchuangYu/ggtree/blob/master/R/method-fortify.R#L185.

So that I have a setup_tree_data function to keep non-duplicated one for drawing branches and labels, etc.

So, in your case, only tip labels of tree_1 were plotted.

If I fixed this bug, then I should remove the support of phyloseq.

I will think about it to figure out a better way. Don't hesitate to let me know, if you have ideas.

brj1 commented 5 years ago

It now works in my fork. See #222 . Though I think this functionality should be available in ggtree proper at some point.