[R-sig-Geo] Plot spatial time series

Thiago Veloso thi_veloso at yahoo.com.br
Tue Jun 12 14:31:12 CEST 2012


  Hi Oscar,

  I reproduced your example in my computer and the final graphic is fine. However, I was not brave enough to stack 506 rasters and test with my data.

  Thanks and best regards,
  Thiago.


----- Original Message -----
From: Oscar Perpiñán Lamigueiro <oscar.perpinan at gmail.com>
To: Thiago Veloso <thi_veloso at yahoo.com.br>
Cc: Matt Landis <landis at isciences.com>; R-SIG list <r-sig-geo at r-project.org>
Sent: Monday, June 11, 2012 5:57 AM
Subject: Re: Plot spatial time series

Thiago Veloso <thi_veloso at yahoo.com.br> writes:
Hello,

Another approach is to use the zoo package with setZ and cellStats. 

With a toy example:

library(raster)
library(zoo)

fn <- system.file("external/test.grd", package="raster")
r <- raster(fn)
ll <- lapply(runif(12), function(x)r*x)
s <- stack(ll)

idx <- as.yearmon(2011 + seq(0, 11)/12)
s <- setZ(s, idx)
avg <- zoo(cellStats(s), idx)

## plot method for the zoo objects
plot(avg)

## or with lattice, xyplot method for the zoo objects
library(lattice)
xyplot(avg)

Best,

Oscar.
>   Matthew,
>
>   Thank you very much for the suggestion. You assumed correctly: I wanted to plot an average of the whole raster.
>
>   I managed to plot the data (please see http://img137.imageshack.us/img137/601/screenshotan.png), but it's still precarious. Right now I am tying to improve the plot with ggplot2 package!
>
>   Cheers,
>   Thiago.
>
>
> ----- Original Message -----
> From: Matt Landis <landis at isciences.com>
> To: Thiago Veloso <thi_veloso at yahoo.com.br>
> Cc: R-SIG list <r-sig-geo at r-project.org>
> Sent: Friday, June 8, 2012 3:45 PM
> Subject: Re: [R-sig-Geo] Plot spatial time series
>
> Fixing typos:
> tmp.df <- data.frame(date = rep(NA, length(files)), lai = NA)
> for ( i in 1:length(files) ){
>      f <- files[i]
>    cat('Reading file: ', f, '\n')
>    tmp.df$date[i] <- regmatches(f, regexpr('[0-9]{7}', f))
>    tmp.df$lai[i] <- mean(getValues(r), na.rm = TRUE)
> }

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan




More information about the R-sig-Geo mailing list