[R-sig-Geo] problem saving spplot in a loop

Henk Sierdsema Henk.Sierdsema at sovon.nl
Mon Dec 7 15:15:31 CET 2009

```Hi Alex,

You have to assign the plot to a temporary variable (like tmp <- spplot(...)) and then use print(tmp1) to save it in the png-file

so somethink like:

tmp <- spplot(...)
png(filename=...)
print(tmp)
dev.off()

Succes!

Henk
-------------------------

Henk Sierdsema

SOVON Vogelonderzoek Nederland / SOVON Dutch Centre for Field Ornithology

Rijksstraatweg 178
6573 DG Beek-Ubbergen
The Netherlands
tel: +31 (0)24 6848145
fax: +31 (0)24 6848122

-----Oorspronkelijk bericht-----
Van: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch]Namens Alexandre VILLERS
Verzonden: maandag 7 december 2009 15:09
Aan: Aide R SIG GEO
Onderwerp: [R-sig-Geo] problem saving spplot in a loop

Hey,

I wrote a loop and want to save plots of multiple
SpatialPolygonDataFrame objects with something like

height=1000, width=2000,res=300)
b<-spplot(grTs[,c("PGRobs04","PGRobs48")],
col.regions=palAb(30)
dev.off()

and

height=1000, width=3000,res=300)
spplot(grTs[,c("ov2000","ov2004","ov2008")],
col.regions=palAb(17),at=cutsAb)
dev.off()

When I run "manually" the code (specifying the l and j values for the
loop), everything is fine and I get nice png files. When the code loops
on its own, I get blank images. I suspect this is a problem of the time
taken by spplot to build the image in time for saving in the loop.
Is this correct and how can I properly overcome this problem ?

Best regards

Alex

--
Alexandre Villers
PhD Candidate
AgriPop
Centre d'Etudes Biologiques de Chizé-CNRS UPR1934
79360 Beauvoir sur Niort

Phone +33 (0)5 49 09 96 13
Fax   +33 (0)5 49 09 65 26

__________ Information from ESET Mail Security, version of virus signature database 4667 (20091207) __________

The message was checked by ESET Mail Security.
http://www.eset.com

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

```