<p>A <a href="https://guangchuangyu.github.io/ggtree">ggtree</a> user recently asked me the following question in <a href="https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/bioc-ggtree/6ec5krxpBMc/sd6jr53KBQAJ">google group</a>:</p>
<blockquote>
<p>I try to plot long tip labels in ggtree and usually adjust them using xlim(), however when creating a facet_plot xlim affects all plots and minimizes them.</p>
<p>Is it possible to work around this and only affect the tree and it’s tip labels leaving the other plots in facet_plot unaffected?</p>
</blockquote>
<p>This is indeed a desire feature, as <code>ggplot2</code> can’t automatically adjust <code>xlim</code> for text since the units are in two different spaces (data and pixel).</p>
<p>Here is an example, the tip labels are truncated.</p>
<pre><code>set.seed(2016-10-31)
tr =rtree(50)
tr$tip.label = paste(tr$tip.label, tr$tip.label, sep=&quot;_&quot;)
p &lt;- ggtree(tr) + geom_tiplab(align=TRUE) + theme_tree2()
d = data.frame(id = tr$tip.label, v= rnorm(50))

facet_plot(p, geom=geom_point, data=d, mapping=aes(x=v), panel='dot') + 
        ggtitle(&quot;truncated tip labels&quot;)
</code></pre>
<p></p>
<p>If we only visualize the tree, it is easy to solve by using <code>xlim()</code> to allocate more space for the lables. But <code>xlim()</code> works for all panels. Combination of <code>facet_plot()</code> and <code>xlim()</code> will produce figure with many spaces.</p>
<pre><code>facet_plot(p+xlim(NA, 6), geom=geom_point, data=d, mapping=aes(x=v), panel='dot') + 
        ggtitle(&quot;xlim applies to all panels&quot;)
</code></pre>
<p></p>
<p>To overcome this issue, <code>ggtree</code> provides <code>xlim_tree</code> to set <code>x</code> axis limits for only the <code>Tree</code> panel.</p>
<pre><code>facet_plot(p+xlim_tree(6), geom=geom_point, data=d, mapping=aes(x=v), panel='dot') + 
        ggtitle('*xlim_tree* only change x axis limits of *Tree* panel')

# or using:
# facet_plot(p, geom=geom_point, data=d, mapping=aes(x=v), panel='dot') + xlim_tree(6)
</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>