title: R annotate phylogenetic tree with external data?
body: <p>I'm using the <code>ggtree</code> package from Bioconductor to plot two phylogenetic trees.  It works essentially like ggplot2, and I want to modify the aesthetics of the tip labels to match classes set by an external CSV file.</p>
  
  <p>I have a multiPhylo object that contains two different clusterings of the same 50 genes (we'll pretend there are only 6 for this example). When I evaluate <code>multitree[[1]]$tip.label</code> and <code>multitree[[2]]$tip.label</code> they both give me the same list in the same order, so I know that while the plots are displayed differently, the genes are still stored in the same order.</p>
  
  <pre><code>library(ggtree)
  library(ape)
  
  mat &lt;- as.dist(matrix(data = rexp(200, rate = 10), nrow = 6, ncol = 6))
  nj.tree &lt;- nj(mat)  ### Package ape
  hclust.tree &lt;- as.phylo(hclust(mat))
  multitree &lt;- c(nj.tree, hclust.tree)
  </code></pre>
  
  <p>I want to plot these trees and then annotate them with external data based on which of 5 classes (A, B, C, D, and E) they are according to existing literature. </p>
  
  <pre><code>write.csv(multitree[[1]]$tip.label, "Genes.csv")
  </code></pre>
  
  <p>I used this command to create a CSV file of each of the genes in the right order (not sure if that's relevant). I then manually entered the corresponding class letter in the column adjascent to each gene. It looks something like this:</p>
  
  <pre><code>Gene    Class
  1       A
  2       A
  3       D
  4       C
  5       B
  6       E
  </code></pre>
  
  <p>And so on. </p>
  
  <p>I want to annotate the tip labels colors on my tree to correspond to the colors defined in my external CSV table. I know it would look something like <code>geom_tiplab(aes(color=something something something))</code>, but I don't know how to make it so that it reads the data inside my CSV and not the data within the <code>multitree</code>. Here's what my ggtree command looks like</p>
  
  <pre><code>myTree &lt;- ggtree(multitree[[i]], aes(x, y)) + 
      ggtitle(names(multitree)[i]) + 
      geom_tiplab() +   ### What I want to annotate with color
      theme_tree2() + 
      coord_fixed(ratio = 0.5) 
  print(myTree)         ###Occurs within a for loop, forces ggplot output to display
  </code></pre>