Skip to content
Prev 18717 / 29559 Next

Help: Individual plots all raster in a raster stack in loop

Thank you so much.
 It works with following code:

saveGIF(
print(spplot(s, layout=c(1, 1))),
height = 500, width = 350, interval = .3, outdir = getwd())

-----Original Message-----
From: Oscar Perpi??n Lamigueiro [mailto:oscar.perpinan at gmail.com] 
Sent: Wednesday, July 03, 2013 2:56 AM
To: Andrew Vitale; Zia Uddin Ahmed
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] Help: Individual plots all raster in a raster stack in loop

Hello,

Instead of using lapply, you can define layout=c(1, 1):

library(raster)

fn <- system.file("external/test.grd", package="raster") r <- raster(fn)
r2 <- raster(fn)+runif(ncell(r))
r3 <- raster(fn)+runif(ncell(r))
r4 <- raster(fn)+runif(ncell(r))
s <- stack(r, r2,r3, r4)

spplot(s, layout=c(1, 1))


On the other hand, you may be interested in this stackoverflow Q&A about animated plots:
http://stackoverflow.com/questions/1298100/creating-a-movie-from-a-series-of-plots-in-r

Last, there is a FAQ about the use of lattice/ggplot2 inside loops:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

Best,

Oscar.

Andrew Vitale <vitale232 at gmail.com> writes:
--
Oscar Perpi??n Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM) Dpto. Ingenier?a El?ctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan
LinkedIn: http://www.linkedin.com/in/oscarperpinan