[R-sig-Geo] Excessive whitespace in saved images from sp::plot()

Michael Sumner mdsumner at gmail.com
Tue Dec 15 20:48:25 CET 2015


Try changing the aspect ratio, asp="" from memory to 'fill the device'. You
might also need par(xpd=NA) or similar to remove the axis buffering.

R and sp generally plot within a figure space, rendering to a "world space"
within a file is not directly supported (writeGDAL and writeRaster do this,
but not for rendering 'layers'). But with careful handling you can do it.

I think external georeferencing would be required for downstream spatial
use, but I am hoping to be corrected on that point(?)

Cheers, Mike

On Wednesday, December 16, 2015, Matt Strimas-Mackey <strimas at zoology.ubc.ca>
wrote:
> I'm trying to plot simple SpatialPolygons objects using the basic
> plot() command from sp and save these as png or svg. For context, this
> is part of a rmarkdown report that will eventually go on the web, so
> the saving of images will be done automatically via knitr. Since this
> involves images, I've put the code and images online:
>
https://github.com/mstrimas/mstrimas.github.io/tree/master/_source/print-problems
>
> My problem is excessive whitespace around the plots:
>
> library(sp)
> par(mar=c(0, 0, 0, 0))
> png('png-dev-400x400.png', width = 400, height = 400)
> plot(square, axes = F)
> dev.off()
>
> But only when saving with a direct call to png() or svg(). Plotting,
> then saving interactively via RStudio or with
>
> dev.print(png, 'dev-print-400x400.png', width = 400, height = 400)
>
> yields a nice plot with no whitespace.
>
> I only encounter this problem when plotting spatial objects, which is
> why I'm posting here. Since these are simple polygons with no
> attributes, I'd prefer to avoid using spplot(). Also, I've tried this
> on 2 machines: a Mac and a PC running Ubuntu, in both cases running
> the latest version of R and the sp package.
>
> Thanks!
>
> M
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list