title: Background Color of grid.arrange in gridExtra
body: <p>So I am trying to draw a few ggplots and their legend using gridExtra. The legend appears in the last cell on a white background - I would like to change the background color there, so that white background disappears. How can I do that?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>library(reshape)
  library(ggplot2)
  library(plyr)
  library(wq)
  library(gridExtra)
  library(lattice)
  library(grid)
  
  testVisualization &lt;- function()
  {
    set.seed(123)
  
    xx &lt;- sample(seq(from = 20, to = 50, by = 5), size = 50, replace = TRUE)
    yy &lt;- sample(seq(from = 1, to = 50), size = 50, replace = TRUE)
    zz &lt;- sample(seq(from = 1, to = 10, by = 1), size = 50, replace = TRUE)
  
    dd &lt;- data.frame(xx,yy,zz)
  
    colRainbow &lt;- rainbow(n, s = 1, v = 1, start = 0, end = max(1, n - 1)/n, alpha = 1)
    gg &lt;- ggplot() + geom_point(data=dd, aes(x=xx, y=yy, colour=zz))+
      theme_custom()
  
    lay2 &lt;- rbind(c(1,1,1,1,1), 
                  c(2,2,3,3,4))
    legg1 &lt;- g_legend(gg)
  
    grid.arrange( 
      gg+guides(fill=FALSE, colour=FALSE, size=FALSE),
      gg+guides(fill=FALSE, colour=FALSE, size=FALSE),
      gg+guides(fill=FALSE, colour=FALSE, size=FALSE),
      legg1,
      layout_matrix=lay2)
  }
  
  theme_custom &lt;- function()
  {
    theme(
      plot.background = element_rect(fill = "#002B36", colour = "#002B36"),
      panel.background = element_rect(fill = "#002B36"),
      panel.background = element_rect(fill = "#002B36"),
      legend.background = element_rect(fill="#002B36", colour = "#002B36"),
      legend.margin = unit(c(-4, -4), "cm"),
      legend.key = element_rect(fill="#002B36", colour ="#002B36"),
      legend.text =element_text(colour = "#DCD427"),
      legend.title=element_text(colour = "#DCD427")
  
    )
  }
  
  g_legend&lt;-function(a.gplot){
    tmp &lt;- ggplot_gtable(ggplot_build(a.gplot))
    leg &lt;- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
    legend &lt;- tmp$grobs[[leg]]
    #+ legend.margin = unit(-0.5, "cm")
    legend
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/J7WAc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J7WAc.png" alt="And here&#39;s the plot I get. I would like the white spaces around the legend cell to disappear"></a></p>