[R-sig-Geo] problem with plotting .pngs with the rasterVis package

Oscar Perpiñan Lamigueiro oscar.perpinan at upm.es
Mon Jan 30 13:41:37 CET 2012


Hi, 

I think you would find useful the "layout" argument of levelplot:

library(raster)
library(rasterVis)

r <- raster(nrows=10, ncols=10)
r <- setValues(r, 1:ncell(r))
s <- stack(r,r*2)
s2 <- stack(s, s, s)*rep(1:3, each=2)

trellis.device(pdf, file='test.pdf')
levelplot(s2, layout=c(2, 1))
dev.off()

By the way, if you use levelplot inside a for loop, you have to print
it:

for (i in 1:3){print(levelplot(s*i))}

Best,

Oscar.

-------------------
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

-----------------------------------------
>hello all,
>I got a problem with the rasterVis package.
>I tried to do some plots in a loop and write every plot with Cairo to
>disc. But the picture in the file on the disc is totaly black or a
>white.
>
>Do somebody know how to make png/pdf levelplots in a loop?
>
>here is my test-script
># problem with RasterVis plots in loops
>#
>###############################################################################
>
>library(raster)
>library(Cairo)
>library(rasterVis)
>
># create RasterLayer / Stack
>r <- raster(nrows=10, ncols=10)
>r <- setValues(r, 1:ncell(r))
>s <- stack(r,r*2)
>
>
># single plot is done
>CairoPNG(width = 400, height = 400, filename="test.png")
>    levelplot(s)
>dev.off()
>
># plot in a loop: no plots are done!
>for(i in 1:3){
>    print(paste("Cairo loop",i))
>    levelplot(s*i)
>}
>
># plot in a loop with cairo: plots are black
>for(i in 1:3){
>    print(paste("Cairo loop",i))
>    CairoPNG(width = 400, height = 400, filename="test.png")
>        levelplot(s*i)
>    dev.off()
>}
>
>	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list