Skip to content
Back to formatted view

Raw Message

Message-ID: <20120130134137.36d4163f@OPL-EUITI>
Date: 2012-01-30T12:41:37Z
From: Oscar PerpiƱan
Subject: problem with plotting .pngs with the rasterVis package
In-Reply-To: <CAMn_rTZ_nQGLh7tXvFnVm=RhEvs3NXXGVmnbc8cdC20qamKLCg@mail.gmail.com>

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