title: In ggplot2 and facet_wrap, how to remove all margins and padding yet keep strip.text?
body: <p>This might primarily be a result of me misunderstanding how <code>panel.margin = unit(...)</code> works in the <code>theme()</code> function...but I'm unable to customize margins in facet_wrap the way that I'd like. Basically, I want a facet_grid that looks like this, with facet text (i.e. <code>strip.text</code>) inset in each facet and no spcaing between each facet:</p>
  
  <p>(I've left in the pink borders to show the dimensions of each facet)</p>
  
  <p><a href="https://i.stack.imgur.com/kE4xE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kE4xE.png" alt="The ideal final product"></a></p>
  
  <p>So here's the code so far.</p>
  
  <p>To set up the data and plot:</p>
  
  <pre><code>library(ggplot2)
  library(grid)
  p &lt;- ggplot() +
    geom_bar(data = mtcars, aes(x = cyl, y = qsec), stat = 'identity') +
    facet_wrap( ~ carb, ncol = 3)
  
  mytheme &lt;- theme_minimal() + theme(
    axis.text.x = element_blank(),
    axis.text.y = element_blank(),
    axis.ticks = element_blank(),
    axis.title = element_blank(),
    panel.margin = unit(0, "lines"),
    panel.border = element_rect(colour = rgb(1.0, 0, 0, 0.5), fill=NA, size=1)
  )
  </code></pre>
  
  The standard plot
  
  <pre><code> p + mytheme
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/TOXLf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/TOXLf.png" alt="just a standard plot"></a></p>
  
  Removing the strip.text completely
  
  <pre><code>p + mytheme + theme(strip.text = element_blank())
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/PzVIK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PzVIK.png" alt="no strip text"></a></p>
  
  Adding the strip.text and insetting it
  
  <pre><code>p + mytheme +
       theme(strip.text = element_text(size = rel(3.0), vjust = -4.0))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/UIenY.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UIenY.png" alt="test grid inset text"></a></p>
  
  <p>The re-inclusion of strip.text (and the increased relative size) increases the vertical margin between the two rows. So at this point, I don't know how to close the vertical gap between the top and bottom rows.</p>
  
  Too much negative margin
  
  <pre><code>p + mytheme +
      theme(strip.text = element_text(size = rel(3.0), vjust = -4.0), 
            panel.margin = unit(c(-2, -2), "lines"))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fpGhI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fpGhI.png" alt="Too much negative margin"></a></p>
  
  <p>So how do I target just the panel.margin between the two rows?</p>
  
  <p><strong>Edit:</strong> Additional information. The space between the rows appears to be <code>strip.background</code>:</p>
  
  <pre><code>p + mytheme +
          theme(strip.text = element_text(size = rel(3.0), vjust = -4.0),
                panel.margin = unit(-1, "lines"),
                strip.background = element_rect(fill = rgb(0, 1.0, 0, 0.2)))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CysJ7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CysJ7.png" alt="enter image description here"></a></p>