YuLab-SMU / treeio

:seedling: Base Classes and Functions for Phylogenetic Tree Input and Output
https://yulab-smu.top/treedata-book/
94 stars 24 forks source link

problem #89

Closed svedwards closed 1 year ago

svedwards commented 1 year ago

I am simply having trouble producing a tree with branches colored as expected. Using the "plotBranchbyTrait" function in phytools produces the expected result, but after full_joining the data to the tree, the resulting ggtree plot looks quite different. This is not a bug but I just don't understand how to align the node numbers in the tree with the rows in the data table. With plotBranchbyTrait it seems straightforward but with ggtree I get an unexpeted/confusing result. Thank you for any tips. I have checked the examples online extensively (dn/ds example, Anolis example) but I can't seem to transfer those examples to my data. Thank you for any suggestions - Scott E.

Prerequisites

shortedgetab.txt Phyl_correct_ATAC_tree.tre.txt

Describe your issue

library(phytools) library(ggtree) tree3<-read.tree("Phyl_correct_ATAC_strict_brlen.txt") shortedgetab<-read.table("shortedgetab.txt",header=T,sep="\t") plotBranchbyTrait(tree3,shortedgetab$sumconv) #gives expected tree figure with branches colored as expected edgelabels(text = shortedgetab$sumconv) edgelabels(adj=c(0.5,2.5))

tree4 <- full_join(tree3, shortedgetab, by = 'node')#works without error ggtree(tree4, aes(color=sumconv), ladderize = FALSE, size=2) + scale_color_continuous(low='darkblue', high='red') + geom_nodelab() + theme(legend.position="right") + geom_tiplab() + geom_text(aes(x=branch, label=sumconv), size=3, vjust=-1.5, color="firebrick") + geom_label(aes(x=branch, label=node),size=2)

produces a tree with different node numbers and colors compared to phytools result

ggtree_atac_nodelabels.pdf Phytools_branch_color_tree_19k_labeled.pdf

I attach the phytools result with the edges labeled and colored as expected, and the ggtree result, with node numbers and colors not expected.

GuangchuangYu commented 1 year ago
  1. you did not provide the tree to reproduce
  2. the edgelabels is not labeling the tree with node number but edge number. So this is not comparable with using ggtree to label with node number.
  3. You can check the table file with the data plotted in the figures.

For example, the first line:

image

It is correct with ggtre:

image

not correct with phytools;

image