<p><a href="https://guangchuangyu.github.io/ggtree">ggtree</a> provides <code>gheatmap</code> for visualizing heatmap with phylogenetic tree and <code>msaplot</code> for visualizing multiple sequence alignment with phylogenetic tree.</p>
<p>We may have different data types and want to visualize and align them with the tree. For example, <code>dotplot</code> of SNP site (e.g. using <code>geom_point(shape='|')</code>), <code>barplot</code> of trait values (e.g. using <code>geom_barh(stat='identity')</code>) et al.</p>
<p>To make it easy to associate different types of data with phylogenetic tree, I implemented the <code>facet_plot</code> function which accepts a <code>geom</code> function to draw the input <code>data.frame</code> and display it in an additional <code>panel</code>.</p>
<blockquote class="twitter-tweet"><p dir="ltr" lang="en">associate tree with different type of data by <a href="https://twitter.com/hashtag/ggtree?src=hash">#ggtree</a> <a href="https://t.co/6w755VWytZ">https://t.co/6w755VWytZ</a> <a href="https://t.co/K8WViEi13E">pic.twitter.com/K8WViEi13E</a></p>— Guangchuang Yu (@guangchuangyu) <a href="https://twitter.com/guangchuangyu/status/773359054924095488">September 7, 2016</a></blockquote>
<pre><code>tr &lt;- rtree(30)
p &lt;- ggtree(tr)
d1 &lt;- data.frame(id=tr$tip.label, location=sample(c(&quot;GZ&quot;, &quot;HK&quot;, &quot;CZ&quot;), 30, replace=TRUE))
p1 &lt;- p %&lt;+% d1 + geom_tippoint(aes(color=location))
d2 &lt;- data.frame(id=tr$tip.label, val=rnorm(30, sd=3))
p2 &lt;- facet_plot(p1, panel=&quot;dot&quot;, data=d2, geom=geom_point, 
                aes(x=val), color='firebrick') + theme_tree2()
</code></pre>
<p></p>
<p>Most of the <code>geom</code> in <code>ggplot2</code> draw vertical graph object, while for associating graph object with phylogenetic tree, we need horizontal versions. Luckily, we have <a href="https://github.com/lionel-/ggstance">ggstance</a> which provides horizontal versions of <code>geoms</code>, including:</p>
<ul><li><code>geom_barh()</code></li>
<li><code>geom_histogramh()</code></li>
<li><code>geom_linerangeh()</code></li>
<li><code>geom_pointrangeh()</code></li>
<li><code>geom_errorbarh()</code></li>
<li><code>geom_crossbarh()</code></li>
<li><code>geom_boxploth()</code></li>
<li><code>geom_violinh()</code></li>
</ul><p>With <code>ggstance</code>, we can associate <code>barplot</code>, <code>boxplot</code> or other graphs to phylogenetic trees.</p>
<pre><code>d3 &lt;- data.frame(id = rep(tr$tip.label, each=2),
                    value = abs(rnorm(60, mean=100, sd=50)),
                    category = rep(LETTERS[1:2], 30))
p3 &lt;- facet_plot(p2, panel = 'Stacked Barplot', data = d3, 
                geom = geom_barh, 
                mapping = aes(x = value, fill = as.factor(category)), 
                stat='identity' ) 
</code></pre>
<p></p>
<pre><code>d4 = data.frame(id=rep(tr$tip.label, each=20), 
                val=as.vector(sapply(1:30, function(i) 
                                rnorm(20, mean=i)))
                )               
p4 &lt;- facet_plot(p3, panel=&quot;Boxplot&quot;, data=d4, geom_boxploth, 
            mapping = aes(x=val, group=label, color=location))                                  
</code></pre>
<p></p>
<h2>Citation</h2>
<p><strong>G Yu</strong>, DK Smith, H Zhu, Y Guan, TTY Lam*. <a href="http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12628/abstract">ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data</a>. <strong>Methods in Ecology and Evolution</strong>. <a href="http://dx.doi.org/10.1111/2041-210X.12628"><code>doi:10.1111/2041-210X.12628</code></a>.</p>
<p></p><div></div>