title: Cropping extra white space in a plot made using ggplot package in R
body: <p>I would like to crop the extra whitespace which results after plotting a plot in ggplot.</p>
  
  <p>I have the following piece of code,</p>
  
  <pre><code>    p1 &lt;- ggplot(d2, aes_string(x=names(sameTLM_df)[1],y= "value")) + 
          geom_point(aes(color = variable), size = 1)+ 
          theme_bw()+
          theme(legend.text=element_text(size=18), legend.title=element_text(size=18))+
          theme(axis.text=element_text(size=20)) +
          theme(axis.title=element_text(size=24,face="bold")) +
   scale_color_discrete(name = "Title", labels = c("1","2","3","4","5","6","7","8","9")) + labs(x = "x", y = "y")+ 
  guides(colour = guide_legend(override.aes = list(size=4))) 
  </code></pre>
  
  <p>which produces a plot like this,</p>
  
  <p><img src="https://i.stack.imgur.com/qkQgs.jpg" alt="enter image description here"></p>
  
  <p>I would like to crop the white background surrounding the plot and change the number of columns in legend to 2, so I use to the following code,</p>
  
  <pre><code>p2 &lt;- p1 + guides(col = guide_legend(ncol = 2)) + theme(plot.background = element_rect(fill = NULL))
  </code></pre>
  
  <p>Which results in a plot such as this,</p>
  
  <p><img src="https://i.stack.imgur.com/3DBo7.jpg" alt="enter image description here"></p>
  
  <p>However the "whitespace" (I have made the background color yellow to illustrate the space between the boundary and plot) is not removed and while the number of columns is changed to 2, the size of the legend list changes as well, which I don't need. Could someone please guide me how to preserve the size of the legend list while changing the columns to 2 and removing the extra white space in the outer bounds of the plot.</p>
  
  <p>Thanks</p>