[R-sig-Geo] bitmap plots in loop
Takatsugu Kobayashi
tkobayas at indiana.edu
Tue Jan 22 06:21:28 CET 2008
hi,
I have read a couple of threads about png and jpg not being supported in
R CMD BATCH. So I decided to use bitmap() instead. I would like to
repeat printing jobs 1000 times. I only got empty png files. Doesn't
this loop open bitmap, plot, close bitmap everytime?
rm(list=ls(all=T))
### Include necessary packages
library(sp)
library(maptools)
pts <- c(2,3,4,5,6,7,8,9,10)
for (iter in 1:length(pts))
{
### Define parameters for a grid
start.point <- -pts
cco <- c(start.point,start.point)
csize <- c(1,1)
n <- abs(cco[1]*2)+1
cnum <- c(n,n)
grd <- GridTopology(cco, csize, cnum)
r.grd <- as(grd, "SpatialPolygons")
### Assign some values to grid cells
ID <- sapply(slot(r.grd, "polygons"), function(x) slot(x, "ID"))
resdf <- data.frame(com.time=runif(n^2), row.names=ID)
r.grd.df <- SpatialPolygonsDataFrame(r.grd, resdf)
### save bitmap images s
bitmap(file=paste('output/gridcell',iter,'_new.png',sep=''),type='png256',
width=5, height=5)
spplot(r.grd.df)
dev.off()
}
I appreciate your help.
Taka
More information about the R-sig-Geo
mailing list