An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120130/b7798539/attachment.pl>
problem with plotting .pngs with the rasterVis package
2 messages · Maximilian Reinwand, Oscar Perpiñan
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]]