 Re-sending last message due to awful text layout! I don't know why this happens... Sorry for double-posting.
 Not really, Jan. Please see below:
------------------------------------------------------------------> #Load required packages> library (raster)Loading required package: spraster version 1.9-70 (27-February-2012)> library (ggplot2)> library (reshape2)> > #Load data> deforest <- brick("/home/thiago/Dropbox/defor-3-years.nc")Loading required package: ncdf> > #Probe layer names and plot raster data> layerNames(deforest)[1] "X0.1" "X0.2" "X0.3"> plot(deforest)> > #Convert spatial object to data frame (omitting NAs)> meltR <- melt(as.array(deforest),na.rm=TRUE)> > #Define classes used to count grids> meltR$class <- cut(meltR$value, c(0,0.3,0.6,1))> #Define factors to plot individual years> meltR$X3 <- factor(meltR$X3, labels=c('2000','2001','2002'))Error in factor(meltR$X3, labels = c("2000", "2001", "2002")) :   invalid labels; length 3 should be 1 or 0------------------------------------------------------------------
 And here is sessionInfo output: 
------------------------------------------------------------------> sessionInfo()R version 2.14.1 (2011-12-22)Platform: x86_64-pc-linux-gnu (64-bit)
locale: [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    [7] LC_PAPER=C                 LC_NAME=C                  [9] LC_ADDRESS=C               LC_TELEPHONE=C            [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
attached base packages:[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:[1] ncdf_1.6.6     reshape2_1.2.1 ggplot2_0.9.0  raster_1.9-70  sp_0.9-97     
loaded via a namespace (and not attached): [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.14.1        [5] lattice_0.20-6     MASS_7.3-17        memoise_0.1        munsell_0.3        [9] plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5 scales_0.2.0      [13] stringr_0.6       ------------------------------------------------------------------
 Thanks for the patient help!   Thiago.
--- On Fri, 16/3/12, Thiago Veloso <thi_veloso@yahoo.com.br> wrote:

From: Thiago Veloso <thi_veloso@yahoo.com.br>
Subject: Re: [R-sig-Geo] Displaying temporal variation of raster data
To: "Jan Verbesselt" <janverbesselt@gmail.com>
Cc: "Oscar Perpiñán Lamigueiro" <oscar.perpinan@upm.es>, "R SIG list" <r-sig-geo@stat.math.ethz.ch>
Date: Friday, 16 March, 2012, 20:29

  Not really, Jan. Please see below.
 > #Load required packages> library (raster)Loading required package: spraster version 1.9-70 (27-February-2012)> library (ggplot2)> library (reshape2)> > #Load data> deforest <- brick("/home/thiago/Dropbox/defor-3-years.nc")Loading required package: ncdf> > #Probe layer names and plot raster data> layerNames(deforest)[1] "X0.1" "X0.2" "X0.3"> plot(deforest)> > #Convert spatial object to data frame (omitting NAs)> meltR <- melt(as.array(deforest),na.rm=TRUE)> > #Define classes used to count grids> meltR$class <- cut(meltR$value, c(0,0.3,0.6,1))> #Define factors to plot individual years> meltR$X3 <- factor(meltR$X3, labels=c('2000','2001','2002'))Error in factor(meltR$X3, labels = c("2000", "2001", "2002")) :   invalid labels; length 3 should be 1 or 0
  Here is my sessionInfo:
> sessionInfo()R version 2.14.1 (2011-12-22)Platform: x86_64-pc-linux-gnu (64-bit)
locale: [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    [7] LC_PAPER=C                 LC_NAME=C                  [9] LC_ADDRESS=C               LC_TELEPHONE=C            [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
attached base packages:[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:[1] ncdf_1.6.6     reshape2_1.2.1 ggplot2_0.9.0  raster_1.9-70  sp_0.9-97     
loaded via a namespace (and not attached): [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.14.1        [5] lattice_0.20-6     MASS_7.3-17        memoise_0.1        munsell_0.3        [9] plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5 scales_0.2.0      [13] stringr_0.6       

  Thanks for the patient help!  Thiago.

--- On Thu, 15/3/12, Jan Verbesselt <janverbesselt@gmail.com> wrote:

From: Jan Verbesselt <janverbesselt@gmail.com>
Subject: Re: [R-sig-Geo] Displaying temporal variation of raster data
To: "Thiago Veloso" <thi_veloso@yahoo.com.br>
Cc: "Barry Rowlingson" <b.rowlingson@lancaster.ac.uk>, "Oscar Perpiñán Lamigueiro" <oscar.perpinan@upm.es>, "R SIG list" <r-sig-geo@stat.math.ethz.ch>
Date: Thursday, 15 March, 2012, 18:36

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> 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]]


-----Inline Attachment Follows-----

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

	[[alternative HTML version deleted]]

