[R-sig-Geo] bitmap plots in loop

Roger Bivand Roger.Bivand at nhh.no
Tue Jan 22 09:15:48 CET 2008


On Tue, 22 Jan 2008, Takatsugu Kobayashi wrote:

> 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)

This is lattice graphics, and must be

print(spplot(r.grd.df))

R FAQ 7.22

Roger


> dev.off()
> }
>
> I appreciate your help.
>
> Taka
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list