Hi,
This is a byproduct of the fact that under the hood spplot uses lattice
commands (levelplot and xyplot) to make the plots. This behavior is a
FAQ for lattice commands, and thus spplot. Even shorter than Henk's
suggestion is to use:
png(filename=...)
print(spplot(...))
dev.off()
cheers,
Paul
Henk Sierdsema schreef:
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-boun...@stat.math.ethz.ch
[mailto:r-sig-geo-boun...@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
png(paste("K:/Outarde/ADrien/FigTemp/PGR",l,"_",j,".png",sep=""),
height=1000, width=2000,res=300)
b<-spplot(grTs[,c("PGRobs04","PGRobs48")],
col.regions=palAb(30)
dev.off()
and
png(paste("K:/Outarde/ADrien/FigTemp/Abondance",l,"_",j,".png",sep=""),
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
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo