Another problem I'm having is that when I add the tip labels in the final plot (with trees face to face and connecting lines) the plot gets messy because the labels are behind the lines. Is there any way to make the lines start in the end of the tip labels instead of by the branch?
p1 <- ggtree(x_2) + ggtitle("ML") + theme(plot.title = element_text(hjust = 0.25)) +
geom_hilight(node=113, fill="steelblue", alpha=.6) +
geom_hilight(node=116, fill="yellow", alpha=.6) +
geom_hilight(node=154, fill="green", alpha=.6)
p2 <- ggtree(y_2) + ggtitle("BI") + theme(plot.title = element_text(hjust = 0.25)) +
geom_hilight(node=190, fill="steelblue", alpha=.6) +
geom_hilight(node=112, fill="yellow", alpha=.6) +
geom_hilight(node=142, fill="green", alpha=.6)
# create tibbles from $data
d1 <- p1$data
d2 <- p2$data
# reverse x-axis and set offset to make the tree in the right hand side of the first tree
d2$x <- max(d2$x) - d2$x + max(d1$x) + 1
pp <- p1 + geom_tree(data=d2) + labs(title = "ML vs BI", caption="Programs used to generate the trees: RaxML and MrBayes")
dd <- bind_rows(d1, d2) %>% # bind multiple data frames by row and column
filter(!
is.na(label)) # 'filter' return rows with matching conditions, in this case the 'labels' (tip labels)
pp + geom_line(aes(x, y, group=label), data=dd, color='grey')