1# Author: Robert J. Hijmans
2# Date :  September 2012
3# Version 1.0
4# Licence GPL v3
5
6
7
8setMethod('barplot', 'RasterLayer',
9	function(height, maxpixels=1000000, digits=0, breaks=NULL, col=rainbow, ...)  {
10
11		x <- sampleRegular(height, maxpixels)
12		adj <- length(x) / ncell(height)
13		if (adj < 1) {
14			warning('a sample of ', round(100*adj, 1), '% of the raster cells were used to estimate frequencies')
15		}
16
17		if (!is.null(digits)) {
18			x <- round(x, digits)
19		}
20		if (!is.null(breaks)) {
21			x <- cut(x, breaks)
22		}
23
24		x <- table(x) / adj
25		if (is.function(col)) {
26			col <- col(length(x))
27		}
28		barplot(x, col=col, ...)
29	}
30)
31