Difference between revisions of "Ggtree"

From EEBedia
Jump to: navigation, search
(Read in the Tree File)
Line 58: Line 58:
 
  ggtree(tree)
 
  ggtree(tree)
  
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>ggplot</tt>. The use of <tt>geoms</tt> makes plotting easily extensible, but it is by no means normal <tt>R</tt> syntax.
+
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>ggplot</tt>. The use of <tt>geoms</tt> makes plotting easily extensible, but it is by no means normal <tt>R</tt> syntax.
  
 
====Cite ggtree====
 
====Cite ggtree====

Revision as of 16:18, 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 ggplot. The use of geoms makes plotting easily extensible, but it is by no means normal R syntax.

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.