title: using patchwork to annotate plots that have labels in different positions
body: <p>I use patchwork to assemble plots made with ggplot2. I also use patchwork's <code>plot_annotation()</code> command to automatically annotate the assembled plots—for example, to automatically place &quot;A&quot;, &quot;B&quot;, etc. in the upper right-hand corner of each plot. For the most part, this is easy to do. But when the plots have axis labels in different positions, it is hard to get the annotations in the right positions. Here is a minimal illustration of the problem:</p>
  <pre><code>library(ggplot2)
  library(patchwork)
  
  pLeft &lt;- ggplot(mtcars) + 
    geom_point(aes(mpg, disp)) + 
    scale_y_continuous(&quot;Left-hand panel&quot;, position = &quot;left&quot;)
  
  pRight &lt;- pLeft + 
    scale_y_continuous(&quot;Right-hand panel&quot;, position = &quot;right&quot;)
  
  pLeft + pRight + 
    plot_layout(nrow = 1) &amp; 
    plot_annotation(tag_levels = &quot;A&quot;) &amp; 
    theme(plot.tag.position  = c(.935, .96))
  </code></pre>
  <p>That code produces a two-panel figure. The tag for the first panel, &quot;A&quot;, is in the correct position. But the tag for the second panel, &quot;B&quot;, is not:
  <a href="https://i.stack.imgur.com/hBiQ4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hBiQ4.png" alt="Plot with tag in wrong positions" /></a></p>
  <p>There are several ways to fix the problem. For example, I can specify <code>plot.tag.position</code> separately for each panel:</p>
  <pre><code>pLeft + theme(plot.tag.position  = c(.935, .96)) +
    pRight + theme(plot.tag.position  = c(.785, .96)) + 
    plot_layout(nrow = 1) &amp; 
    plot_annotation(tag_levels = &quot;A&quot;)
  </code></pre>
  <p>Or I can skip <code>plot_annotation()</code> entirely and just use <code>annotation_custom()</code> for each panel. But these are bad solutions. The problem is that they require specifying the tag coordinates separately for each panel. And I will sometimes have many panels in the assembled figure—say, <em>N</em> × 2 panels in a two-column figure. In this case, I would like to specify the coordinates only twice: once for the left-hand column, and once for the right-hand column. Is this possible?</p>
  <p>I've looked to the patchwork website and here on Stack Overflow for relevant posts, but I haven't found any solutions.</p>