title: Opaque legend in an R plot with transparent background?
body: <p>I'm trying to put a legend in an R plot, on top of some grid lines. I want the legend to be opaque, so that the grid lines do not show through the legend. However, I also want the whole image to have a transparent (not white) background, for display on the web.</p>
  
  <p>I know I can do <code>bg="white"</code> to get an opaque legend, but it does not combine well with <code>png(..., bg=transparent)</code>. Example:</p>
  
  <pre><code>    png("test.png", bg="transparent")
      plot(rnorm(10))
      grid()
      legend("topright", legend="foo", bg="white")
      dev.off()
  </code></pre>
  
  <p>When this png is displayed on a website with a coloured background, the colour will show through most of the plot, but the legend will still be white. Is there a way to make the legend "opaque", so that the grid lines don't show through, but still have it transparent in the final png output?</p>