# NOT RUN {
require(raster)
r <- raster(ncols=100, nrows=100)
r[] <- runif(ncell(r), 0, 1)
r <- focal(r, w=focalWeight(r, 6, "Gauss"))
r[sample(1000, 1:ncell(r))] <- NA
# full raster percent volume
p30 <- raster.vol(r, p=0.30)
p50 <- raster.vol(r, p=0.50)
p80 <- raster.vol(r, p=0.80)
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2))
plot(r, col=cm.colors(10), main="original raster")
plot(p30, breaks=c(0,0.1,1), col=c("cyan","red"), legend=FALSE,
main="30% volume")
plot(p50, breaks=c(0,0.1,1), col=c("cyan","red"), legend=FALSE,
main="50% volume")
plot(p80, breaks=c(0,0.1,1), col=c("cyan","red"), legend=FALSE,
main="80% volume")
par(opar)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab