[R-sig-Geo] Displaying temporal variation of raster data

Oscar Perpiñán Lamigueiro oscar.perpinan at upm.es
Thu Mar 15 21:23:54 CET 2012


Barry Rowlingson <b.rowlingson at lancaster.ac.uk> writes:

> On Thu, Mar 15, 2012 at 4:45 PM, Thiago Veloso <thi_veloso at yahoo.com.br> wrote:
>>  Dear Jan (cc Oscar, who also gave a tip),
>>  Thanks for your input. Sorry for not stating my problem concisely. This time I have shared a simplified sample of my data: http://db.tt/XXDtRee1.
>>  Notice that this netcdf file contains three time dimensions - corresponding to years 2000 to 2002 (entire dataset contains ten). Also notice that values range from 0 to 1. As we can see in the file, each year is marked by different degrees of deforestation rates.
>>  Below is the code I am using to load the multi-band file:
>>> library (raster)> deforest<-brick("/home/thiago/Dropbox/defor-3-years.nc"
>
>  From there, I can go:
>
>  > meltR=melt(as.array(deforest))
>  > meltR$class=cut(meltR$value,c(0,0.3,0.6,1))
>  > p = ggplot(meltR,aes(x=class))
>  > p + geom_histogram(aes(fill=class))+facet_grid(~X3)
>
>  And get a very pretty set of histograms. You need the ggplot package.

And for completeness, the lattice way ;-):

layerNames(deforest) <- as.character(2000:2002)

dat <- as.data.frame(deforest)
datLong <- stack(dat) ##wide to long

datLong$class <- cut(datLong$values, c(0, 0.3, 0.6, 1))
tt <- table(datLong$ind, datLong$class)

library(lattice)
barchart(tt, auto.key=list(space='right'), horizontal=FALSE, stack=FALSE)

You can even use the 'cut' method for 'Raster*':

defClass <- cut(deforest, c(0, 0.3, 0.6, 1))
dat <- stack(as.data.frame(defClass))
tt <- table(dat$ind, dat$values)
barchart(tt, auto.key=list(space='right'), horizontal=FALSE, stack=FALSE)

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