Skip to content
Prev 7117 / 29559 Next

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