--- title: "ggtree utilities" author: "Guangchuang Yu and Tommy Tsan-Yuk Lam\\ School of Public Health, The University of Hong Kong" date: "`r Sys.Date()`" bibliography: ggtree.bib csl: nature.csl output: prettydoc::html_pretty: toc: true theme: cayman highlight: github pdf_document: toc: true vignette: > %\VignetteIndexEntry{06 ggtree utilities} %\VignetteEngine{knitr::rmarkdown} %\usepackage[utf8]{inputenc} --- ```{r style, echo=FALSE, results="asis", message=FALSE} knitr::opts_chunk$set(tidy = FALSE, message = FALSE) ``` ```{r echo=FALSE, results="hide", message=FALSE} library("ape") library("ggplot2") library("ggtree") ``` # Layers that allows subsetting `Subsetting` is not supported in layers defined in `ggplot2`, while it is quite useful in phylogenetic annotation since it allows us to annotate at specific node(s). In `ggtree`, we provides modified version of layers defined in `ggplot2` to support `subsetting`, including: + geom_segment2 + geom_point2 + geom_text2 + geom_label2 ```{r fig.width=5, fig.height=5} file <- system.file("extdata/BEAST", "beast_mcc.tree", package="treeio") beast <- read.beast(file) ggtree(beast) + geom_point2(aes(subset=!is.na(posterior) & posterior > 0.75), color='firebrick') ``` # Multiple graphs on one page To support viewing multiple plots, ggtree provides `multiplot` function that similar to `gridExtra::grid.arrange` with extra feature of labeling the plots. ``` {r fig.width=8, fig.height=4, warning=FALSE} multiplot(ggtree(rtree(30)), ggtree(rtree(40)), ncol=2, labels=c('A', 'B')) ```