I am trying to plot several rescaled trees and I need to combine external data.
My situation is different from this example (that combines a beast and ML tree, merge_tree):
in that instead of having two trees to merge, I have a table of the values for all nodes AND tips (see 'edgetable').
I tried combining the data using only the labels (the way it's done in the above example) but I loose the information for the nodes (see middle tree below).
I have an addition issue with using non-numerical dates, since 'mrsd=' doesn't assign the correct date (see tree on the right).
The code is below.
Any suggestions on how to fix these two problems (which are likely related), would be appreciated.
Carmen
egtree <- read.tree("example_tree.nwk") #'phylo' object and edge.length in tree is = clock_length in edgetable
edgetable <-read.csv("edgetable_cladet.csv", header = T)
m <- data_frame(label= egtree$tip.label, mutation_length= edgetable$mutation_length[edgetable$isTip == TRUE] )
d <- data_frame(label= egtree$tip.label, date= edgetable$date[edgetable$isTip == TRUE] )
as.treedata(egtree) -> egtree #now S4 object
full_join(egtree, m, by="label") -> egtree2
full_join(egtree2, d, by="label") -> egtree2
#plot tree (scale is clock length)
p1<- ggtree(egtree2) + geom_tiplab()+
coord_cartesian(clip = 'off') + theme_tree2()+ggtitle("clock length")
#plot rescaled by mutation length
p2<- ggtree(rescale_tree(egtree2, branch.length = 'mutation_length')) + geom_tiplab()+
coord_cartesian(clip = 'off') + theme_tree2()+ggtitle("mutation length")
#extra problem (non-numerical date): scale is incorrect: adds same decimal date to all ticks
p3<- ggtree(egtree2, mrsd = as.Date(max(edgetable$date)))+ geom_tiplab()+
coord_cartesian(clip = 'off') + theme_tree2()+ggtitle("date")
library(cowplot)
plot_grid(p1, p2, p3, ncol=3)