Skip to content
Prev 19734 / 29559 Next

Select and plot specific row in rasterstack

Hello,

You can extract a row from a RasterStack with s[i,]. Try this code:
 
library(raster)
library(zoo)
library(lattice)

r <- raster(nrow=20, ncol=5)
s <- stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )
## assign a time index to the 'RasterStack'
s <- setZ(s, seq(Sys.Date()-4, by='day', length=5))

## extract a row (10) and convert the result (a 'matrix') into a 'zoo'
## object using the time index of the 'RasterStack' object
zz <- zoo(t(s[10,]), order.by=getZ(s))

xyplot(zz, superpose=TRUE)


Best,

Oscar.
Eddie Smith writes: