geom_hilight in reversed x-axis

164 views
Skip to first unread message

Gustavo Miranda

unread,
Jan 9, 2020, 4:32:05 PM1/9/20
to ggtree
Hello,

I am creating a plot with two phylogenetic trees with connected tips (Fig.3 attached) and I am having problems highlighting the clades of interest in the reversed x-axis. The geom_hilight works fine for the individual trees (Fig. 1 and 2 attached), but I not managing to make it work when the axis is reversed. Does anyone knows how to solve this problem?


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?


Here is a piece of the code I am working with:

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')




Thank you!
Gustavo
Fig.2-ML.pdf
Fig.3-MLvsBI.pdf
Fig.1-BI.pdf

Yu, Guangchuang

unread,
Sep 2, 2020, 11:00:19 PM9/2/20
to Gustavo Miranda, ggtree

Note that you need to install ggtree v >= 2.3.4.993 (currently on github).

image.png


--
1. LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu*. treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. Molecular Biology and Evolution. 2019, accepted. http://dx.doi.org/10.1093/molbev/msz240
2. G Yu*, TTY Lam, H Zhu, Y Guan*. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution, 2018, 35(2):3041-3043. https://doi.org/10.1093/molbev/msy194
3. G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. https://doi.org/10.1111/2041-210X.12628
4. Book: https://yulab-smu.github.io/treedata-book/
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/5d9beb45-06d4-4402-ab66-20b78dbe26fe%40googlegroups.com.


--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu PhD
Professor, Associate Director
Department of Bioinformatics
School of Basic Medical Sciences
Southern Medical University
Guangzhou, China
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages