title: R: layout() affects margin size in plot regions
body: <p>I am having problems trying to automatically generate composite figures in R with different numbers of panels. When I have 3 or more panels in my figure, the margins are significantly different (smaller in the 1x3 plot), enough to cause R to plot labels incorrectly and detracting from the overall look.</p>
  
  <pre><code># plot empty plot with box around plot and figure
  plot_box &lt;- function() {
          plot(1, 1, type='n', bty='n', xaxt='n', yaxt='n', xlab='', ylab='')
          box(lwd = 6)
          box("figure", lwd=6, col='red')
  }
  
  png("box_test1.png", width=1000, height=500)
  par(oma=c(0,0,0,0))
  layout(t(1:2))
  par(mar=c(3, 3, 3, 3))
  plot_box()
  par(mar=c(3, 3, 3, 3))
  plot_box()
  dev.off()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qfXwi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qfXwi.png" alt="box_test1.png"></a></p>
  
  <pre><code>png("box_test2.png", width=1500, height=500)
  par(oma=c(0,0,0,0))
  layout(t(1:3))
  par(mar=c(3, 3, 3, 3))
  plot_box()
  par(mar=c(3, 3, 3, 3))
  plot_box()
  par(mar=c(3, 3, 3, 3))
  plot_box()
  dev.off()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/r0lJA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/r0lJA.png" alt="box_test2.png"></a></p>
  
  <p>The images are scaled for display on stack overflow but as you can see from the device calls they are the exact same size.</p>
  
  <p>This issue is very confusing to me and in all honestly feels like a bug, however I know the R plotting code is very mature so I'm hopeful for a solution.</p>