Difference between revisions of "Ggtree"

From EEBedia
Jump to: navigation, search
(Getting Started)
Line 59: Line 59:
  
 
What happened to our tree!? The <tt>plot</tt> function from the <tt>graphics</tt> package simply, but stubbornly, plots your tree without much ability to alter aesthetics. <tt>ggtree</tt> by default plots almost nothing, assuming you will add what you want to your tree plot. You can add elements to the plot using <tt>geoms</tt>, just the same way that you would add elements to plots using the package <tt>ggplot2</tt>. The use of <tt>geoms</tt> makes plotting easily extensible, but it is by no means normal <tt>R</tt> syntax. To see the <tt>geoms</tt> available to <tt>ggtree</tt> check out its [https://www.bioconductor.org/packages/release/bioc/manuals/ggtree/man/ggtree.pdf reference manual on BioConductor].
 
What happened to our tree!? The <tt>plot</tt> function from the <tt>graphics</tt> package simply, but stubbornly, plots your tree without much ability to alter aesthetics. <tt>ggtree</tt> by default plots almost nothing, assuming you will add what you want to your tree plot. You can add elements to the plot using <tt>geoms</tt>, just the same way that you would add elements to plots using the package <tt>ggplot2</tt>. The use of <tt>geoms</tt> makes plotting easily extensible, but it is by no means normal <tt>R</tt> syntax. To see the <tt>geoms</tt> available to <tt>ggtree</tt> check out its [https://www.bioconductor.org/packages/release/bioc/manuals/ggtree/man/ggtree.pdf reference manual on BioConductor].
 +
 +
====Adding/Altering Tree Elements with Geoms====
 +
 +
=====Tip Labels=====
 +
 +
OK this tree would be more useful with tiplabels. Let's add them using <tt>geom_tiplab</tt>:
 +
 +
ggtree(tree)+geom_tiplab()
 +
 +
=====Clade Labels=====
 +
 +
=====Node Labels=====
 +
 +
 +
=====Clade Color=====
 +
 +
 +
=====Scale Bar=====
 +
  
 
====Cite ggtree====
 
====Cite ggtree====

Revision as of 16:44, 7 March 2018

Adiantum.png EEB 5349: Phylogenetics

by Kevin Keegan

Goals

To introduce you to the R package ggtree for plotting phylogenetic trees.

Introduction

Getting Started

Download the tree file (Paul can you host the treefile?)

Installing Packages

Open a terminal, start R, and install the packages we will be using. We'll be using the packages:

BiocInstaller
ape
Biostrings
ggplot2
ggtree
phytools
ggrepel
stringr
stringi
abind
treeio

You can install a package like so:

install.packages("BiocInstaller")

Many of the above packages are part of the Bioconductor project (like ggtree and treeio). You can find extensive documentation on their website for packages associated with their project.

Read in the Tree File

We're dealing with a tree in the Newick file format which the function read.newick from the package treeio can handle:

tree <- read.newick("moth.txt")

R can handle more than just Newick formatted tree files. To see what other file formats from the various phylogenetic software that R can handle treeio

Let's quickly plot the tree to see what it looks like using the regular old plot<tt> function from the <tt>graphics package:

plot(tree)

Notice the tree has all of its tips labeled. It's also a little cramped. You can expand the plot window to try to get the tree to display more legibly. Some trees (like this one) are too big though. No worry -- we'll get around this problem later.

Now plot the tree using the ggtree package:

ggtree(tree)

What happened to our tree!? The plot function from the graphics package simply, but stubbornly, plots your tree without much ability to alter aesthetics. ggtree by default plots almost nothing, assuming you will add what you want to your tree plot. You can add elements to the plot using geoms, just the same way that you would add elements to plots using the package ggplot2. The use of geoms makes plotting easily extensible, but it is by no means normal R syntax. To see the geoms available to ggtree check out its reference manual on BioConductor.

Adding/Altering Tree Elements with Geoms

Tip Labels

OK this tree would be more useful with tiplabels. Let's add them using geom_tiplab:

ggtree(tree)+geom_tiplab()

Clade Labels
Node Labels
Clade Color
Scale Bar

Cite ggtree

citation("ggtree")

References

Yu G, Smith D, Zhu H, Guan Y and Lam TT (2017). “ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data.” Methods in Ecology and Evolution, 8, pp. 28-36. doi: 10.1111/2041-210X.12628, http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12628/abstract.