title: Get current ggplot object
body: <p>Suppose I plot something like this:</p>
  
  <pre><code>ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) + geom_point()
  </code></pre>
  
  <p>Then I realise that I forgot to store the result (i.e. the ggplot object).</p>
  
  <p><strong>How can I retrieve the ggplot object corresponding to the current device?</strong></p>
  
  <p>Is there some <code>ggplot</code> function I can feed <code>cur.dev()</code> into to retrieve the associated plot object, or is it gone forever?</p>
  
  <p>(Note - in this case I could do <code>p &lt;- .Last.value</code>, but let's assume I've typed a few commands since then so that this is not available.</p>
  
  <p>Motivation - adding a hook to <code>knitr</code> to automagically set <code>fig.cap</code> to the title of the plot (if any)).</p>