title: Exporting a levelplot to a png file while keeping the ratio of axes
body: <p>As a follow-up on <a href="https://stackoverflow.com/questions/20054383/adding-a-background-image-to-a-levelplot">Adding a background image to a levelplot</a> I'm exporting the <code>levelplot</code> to a png file, and I'd like to know how I can access the width and height of that trellis object to pass it as parameters to <code>png</code>.</p>
  
  <pre><code>library("png")
  library("lattice")
  library("latticeExtra")
  
  MyFunction &lt;- function(x,y){
    return(
      dnorm(sqrt(x^2+y^2)))}
  
  meshstep &lt;- 0.2
  x&lt;- seq(-30,30,meshstep)
  y &lt;-seq(-20,20,meshstep)
  image &lt;- readPNG(system.file("img", "Rlogo.png", package="png"))
  
  grid &lt;- expand.grid(x=x, y=y)
  
  grid$z&lt;- MyFunction(grid$x,grid$y)
  
  MyPalette &lt;- colorRampPalette(c('white','yellow', 'red'))
  
  levels &lt;- 10
  p&lt;- levelplot(z~x*y, grid, cuts = levels, xlab="",
                  ylab="",
                  colorkey = TRUE, region = TRUE,col.regions=MyPalette(levels+1),
                  alpha.regions=0.5) 
  + layer(grid.raster(as.raster(image)), under=TRUE) 
  
  trellis.device(device="png", filename="MWE.png")
  print(p)
  dev.off()
  </code></pre>
  
  <p>For the resulting png file, the width and height are 480px, since this is the default. I'd like to write <code>trellis.device(device="png", filename="MWE.png", width=width(p), height=height(p))</code> or something similar to keep the x and y axes evenly spaced.</p>