[R-sig-Geo] Displaying temporal variation of raster data
Oscar Perpiñán Lamigueiro
oscar.perpinan at upm.es
Thu Mar 15 11:56:14 CET 2012
Thiago Veloso <thi_veloso at yahoo.com.br> writes:
> Dear R colleagues,
>
> I have a netcdf file containing ten time slices, where each slice corresponds to yearly deforestation rates over the Amazon forest. Values range from 0 (no deforest) to 1 (maximum deforest). Please take a look in a sample of the data: http://imageshack.us/photo/my-images/23/deforestamazon.png/
>
> My objective is to show the temporal variation of this data. How can I produce categorical histograms for each one of the ten years? What I have in mind is something like the lower panel of this figure: http://www.crwr.utexas.edu/gis/gishydro05/Time/DHI_Temporal_Analyst/TemporalAnalystForArcGIS.htm, but plotting bars relative to three or four classes of deforesting rates instead of lines.
>
> Is it possible to produce such a figure using any SIG-related R package?
Hello,
The combination of 'setZ' from raster with 'histogram' (or 'densityplot') from
rasterVis is a suitable solution:
library(raster)
library(rasterVis)
r <- raster(ncol=10, nrow=10)
s <- stack(lapply(1:12, function(x)setValues(r, runif(ncell(r)))))
idx <- seq(as.Date('2000-01-15'), length.out=12, by='month')
s <- setZ(s, idx)
layerNames(s) <- format(idx, '%b')
s
histogram(s)
densityplot(s)
And if you use 'zoo':
library(zoo)
histogram(s, FUN=as.yearqtr)
densityplot(s, FUN=as.yearqtr)
Best,
Oscar.
--
Oscar Perpiñán Lamigueiro
Dpto. de Ingeniería Eléctrica
EUITI-UPM
http://procomun.wordpress.com
More information about the R-sig-Geo
mailing list