title: Resize plot canvas to actual plot size in R with ggplot2
body: <p>One of the features of the R plotting machinery that I use more often is <code>png(file=..., width=..., height=..., res=...)</code>.</p>
  <p>Normally, I set precise values within the function, e.g. <code>png(&quot;out.png&quot;, height=1500, width=2500, res=250)</code>.</p>
  <p>I am now making a tool that makes an automatic plot from the provided dataset, but the tool is agnostic in respect to the number of rows it has to show in the plot, i.e. it plots what it receives. Sometimes, the plot has a large white area around it. Some other times, the canvas is too small and some rows fall outside.</p>
  <p>I'm trying to fix this by calculating height and width according to the number of rows in the dataframe, but I find this approach error prone and suboptimal.</p>
  <p>For example, inkscape has a nice function called &quot;Resize page to drawing or selection&quot; which will resize the canvas to match the boundaries of the plot. You can even pass a certain tolerance value so that your plot will still have <em>some</em> white around it.</p>
  <p>Does R have this possibility, perhaps within <code>ggsave()</code> if not within <code>png()</code>?</p>