[R-sig-Geo] Calculate percent cover in a raster

Ben Tupper btupper at bigelow.org
Wed Feb 17 03:47:37 CET 2016


Hi,

I think you can use raster::reclassify() or raster::cut() to bin your rainfall.

intervals <- seq(from = 0, to = 600, by = 100)
ix <- cut(r, breaks = intervals)
tx <- table(as.vector(ix))
tx

  1   2   3   4   5   6 
 46  64  85  76 100  69 

tx/sum(tx)*100

       1        2        3        4        5        6 
10.45455 14.54545 19.31818 17.27273 22.72727 15.68182 

Is that what you are looking for?


Cheers,
Ben

> On Feb 16, 2016, at 8:51 PM, Thiago V. dos Santos <thi_veloso at yahoo.com.br> wrote:
> 
> Hi all,
> 
> I have a raster at 0.5 degree resolution with monthly totals of rainfall, which range from 50 mm to 600 mm:
> 
> require(raster)
> 
> ## scratch a raster and fill some random values
> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
> r[] <- round(runif(22 * 20, min=50, max=600), digits=0)
> 
> 
> How can I calculate the percentage area of the raster covered with some rainfall ranges? 
> 
> Let's say for example 0 to 100, 101 to 200, 201 to 300, 301 to 400, 401 to 500 and finally 501 to 600 mm? 
> Thanks in advance,
> -- Thiago V. dos Santos
> 
> PhD student
> Land and Atmospheric Science
> University of Minnesota
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org



More information about the R-sig-Geo mailing list