title: How to plot and save tableGrob objects
body: <p>Using <code>ggplot2</code> and <code>gridExtra</code> in R, I have a <code>tableGrob</code> which I want to plot and save.</p>
  
  <p>Let's say it is a small table like this one (you can try it yourself with the biult-in dataset <code>iris</code>):</p>
  
  <pre><code>ggsave(plot=tableGrob(head(iris[,1:3])), filename="test.png")
  </code></pre>
  
  <p>See the result:<a href="https://i.stack.imgur.com/YruHH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YruHH.png" alt="Small table"></a></p>
  
  <p>Wonderful, it works! However... lots of white space is plotted around the table, since <code>ggsave</code> defaults to <code>w=7, h=7</code> (inches), and the table does not scale up to cover that space.
  I could specify <code>w</code> and <code>h</code> manually, but I have to plot <em>many</em> tables and it would be a lot of work to find all the right values.</p>
  
  <p>If I try to plot a larger table:</p>
  
  <pre><code>ggsave(plot=tableGrob(iris), filename="test2.png")
  </code></pre>
  
  <p>...it does not fit anymore!
  <a href="https://i.stack.imgur.com/KZpYP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KZpYP.png" alt="Big table"></a></p>
  
  <p>So, how can I <strong>automatically</strong> tell the plotted table to readjust based on the plot size? Or how can I tell <code>ggsave</code> to adjust the image space to the right size?</p>