Can you provide an example plot otherwise this code does not tell a user what to expect. Use the directions here: How to add images to a Biostars post
Hi, I'm currently working on several (seven) phylogenetic trees and I want to compare them to each other in the same time. I want to find what part of them is consistent.
Does anyone know a good software?
Thanks for help :)
2 answers
Here is a solution with ggtree for face to face trees:
library(ggplot2)
library(ggtree)
library(cowplot)
set.seed(8455)
t1 <- rtree(20)
t2 <- rtree(20)
T1 <- ggtree(t1 ) +
theme_tree2(legend.position='none', plot.margin = unit(c(0,0,0,0),"cm")) +
geom_tiplab()
T2 <- ggtree(t2) +
theme_tree2(legend.position='none', plot.margin = unit(c(0,0,0,0),"cm")) +
geom_tiplab(hjust =1) +
scale_x_reverse()
d1 = T1$data[T1$data$isTip,]
d1$x[] = 1
d2 = T2$data[T2$data$isTip,]
d2$x[] = 2
TTcon <- rbind(d1, d2)
T1 = ggtree(t1 ) +
theme_tree2(legend.position='none', plot.margin = unit(c(0,0,0,0),"cm")) +
geom_tiplab(align = TRUE) # if required + xlim(0,5.2)
T2 = ggtree(t2) +
theme_tree2(legend.position='none', plot.margin = unit(c(0,0,0,0),"cm")) +
geom_tiplab(hjust =1, align = TRUE) +
scale_x_reverse() # if required add within scale_x_reverse() -> limits = c(5.2, 0))
L1 = ggplot(TTcon, aes(x = x, y = y, colour = label, group = label)) + geom_line() +
theme_void() + theme(legend.position="none", plot.margin = unit(c(1,0,1,0),"cm"))
cowplot::plot_grid(T1, L1 ,T2, nrow = 1, align = "hv")

Thanks for the code! However, I find that my lines are not fully aligned. I figure this is because one tree is missing branches in the other, also shown in this example:
t1 <- rtree(50)
t2 <- rtree(20)
T1 <- ggtree(t1 ) +
theme_tree2(legend.position='none', plot.margin = unit(c(0,0,0,0),"cm")) +
geom_tiplab()
T2 <- ggtree(t2) +
theme_tree2(legend.position='none', plot.margin = unit(c(0,0,0,0),"cm")) +
geom_tiplab(hjust =1) +
scale_x_reverse()
d1 = T1$data[T1$data$isTip,]
d1$x[] = 1
d2 = T2$data[T2$data$isTip,]
d2$x[] = 2
TTcon <- rbind(d1, d2)
T1 = ggtree(t1 ) +
theme_tree2(legend.position='none', plot.margin = unit(c(0,0,0,0),"cm")) +
geom_tiplab(align = TRUE) # if required + xlim(0,5.2)
T2 = ggtree(t2) +
theme_tree2(legend.position='none', plot.margin = unit(c(0,0,0,0),"cm")) +
geom_tiplab(hjust =1, align = TRUE) +
scale_x_reverse() # if required add within scale_x_reverse() -> limits = c(5.2, 0))
L1 = ggplot(TTcon, aes(x = x, y = y, colour = label, group = label)) + geom_line() +
theme_void() + theme(legend.position="none", plot.margin = unit(c(1,0,1,0),"cm"))
cowplot::plot_grid(T1, L1 ,T2, nrow = 1, align = "hv")
Is there a way to account for that and only have lines drawn for the matching tip labels?
hello, I have same problem, but I found this is because the padding beteween figure and x axis in line chart. you can chage this by follow this answer on stackoverflow: https://stackoverflow.com/a/52318834.
but I still can't let each line align to each tip perfectly:)
You can do tree comparison with ete2, although I am not sure it is in the way you meant: https://pythonhosted.org/ete2/tutorial/tutorial_trees.html#comparing-trees
Thank you for your response.
The link you sent refers to compering between only 2 trees. I am looking for a software which shall allow me to compare all 7 trees together, in the same time.
Is there anything you may recommend?
I don't know of anything that would do multiple trees. You may have to do multiple pairwise comparisons or compare each tree to some reference tree structure.
Log in to answer this question.