How it works...

This code achieves a lot very quickly. It can do this by virtue of its ggplot-like layer syntax. Here's what each step does and its output:

  1. Load in a tree from a file. The tree here has 191 tips, so it's quite large. It happens to be in Newick format, so we use the ape read.tree() function. Note that we don't need to have a treedata object for ggtree in subsequent steps; the phylo object returned from read.tree() is perfectly acceptable to ggtree().
  2. Create a basic tree with ggtree(). This function is a wrapper for a longer ggplot-style syntax, specifically, ggplot(itol) + aes(x,y) + geom_tree() + theme_tree(). Hence, all the usual ggplot functions can be used as extra layers in the plot. The code in this step gives us the following plot:

  1. Change the layout of the plot. Setting the layout argument to circular gives us a round tree. There are many other tree types available through this argument:

  1. We can change the left-right direction of the tree to a top-bottom one using the standard ggplot functions, coord_flip() and scale_x_reverse(), to make the plot look like this:

  1. We can add names to the end of the tips with geom_tiplab(). The size argument sets the text size. This code generates the following output:

  1. By adding a geom_strip() layer, we can annotate clades in the tree with a block of color. The first argument (13 in this instance) is the start node in the tree, while the second argument is the end node in the tree for the strip of color. The barsize argument sets the width of the color block. The result looks like this:

  1. We can highlight clades in unrooted trees with blobs of color using the geom_hilight_encircle() geom. We need to pick a value for the node argument, which tells ggtree() which node to center the color over. The code here provides the following output:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.116.50