this solves the error:

library (raster)
deforest<-brick("/Users/janvb/Dropbox/data/Brazil/Tiago/defor-3-years.nc")
layerNames(deforest)
plot(deforest)
meltR = melt(as.array(deforest))
meltR$class = cut(meltR$value,c(0,0.3,0.6,1))
meltR$X3 = factor(meltR$X3, labels=c('2000','2001','2002'))
meltR = na.omit(meltR)
p =  ggplot(meltR,aes(x=class))
p + geom_histogram(aes(fill=class)) + facet_grid(. ~ X3)
# p + geom_bar(aes(X3, fill=class)) + coord_flip() # alternative but not as
nice.


cheers,
J

On Thu, Mar 15, 2012 at 9:08 PM, Thiago Veloso <thi_veloso@yahoo.com.br>wrote:

>  Barry,
>
>  Thank you very much. In R, with only a few lines, powerful things happen!
>
>  Hasn't ggplot been discontinued? I have ggplot2 instead (and needed to
> manually load package "reshape2" to access function melt), and your code
> goes well until the last line, where the following error appears:
>
> > p + geom_histogram(aes(fill=class))+facet_grid(~X3)Error in layout_base(data, cols, drop = drop) :
>   At least one layer must contain all variables used for facetting
>
>
>  If I supress facet_grid, I receive a unique histogram, counting data from
> the three years: http://img24.imageshack.us/img24/8871/rplot.png.
>
>  Any clues?
>
>  Best,
>  Thiago.
>
>  P.S.: This "over 1" value certainly arose as residue from interpolation
> techniques...
>
>
> --- On *Thu, 15/3/12, Barry Rowlingson <b.rowlingson@lancaster.ac.uk>*wrote:
>
>
> From: Barry Rowlingson <b.rowlingson@lancaster.ac.uk>
>
> Subject: Re: [R-sig-Geo] Displaying temporal variation of raster data
> To: "Thiago Veloso" <thi_veloso@yahoo.com.br>
> Cc: "Jan Verbesselt" <janverbesselt@gmail.com>, "Oscar Perpiñán
> Lamigueiro" <oscar.perpinan@upm.es>, "R SIG list" <
> r-sig-geo@stat.math.ethz.ch>
> Date: Thursday, 15 March, 2012, 14:58
>
>
> On Thu, Mar 15, 2012 at 4:45 PM, Thiago Veloso <thi_veloso@yahoo.com.br<http://mc/compose?to=thi_veloso@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.
>
> You might want to get rid of the NA values - note that one of the
> values in your data is greater than 1, contrary to what you said!
>
> > range(meltR$value,na.rm=TRUE)
> [1] 0.000006 1.000662
>
> Barry
>
>

	[[alternative HTML version deleted]]

