R: Histogram of Raster objects.

histogram-methods {rasterVis} | R Documentation

## Histogram of Raster objects.

### Description

Draw histograms (with `lattice`) of Raster objects.

### Usage

    ## S4 method for signature 'RasterLayer,missing'
    histogram(x, data=NULL, maxpixels = 1e+05, nint=100,
                xlab='', ylab='', main='', col='gray', ...)

    ## S4 method for signature 'RasterStackBrick,missing'
    histogram(x, data=NULL, layers, FUN,
                maxpixels = 1e+05, nint=100,
                xlab='', ylab='', main='', col='gray',
                between=list(x=0.5, y=0.2),
                as.table=TRUE,
                scales=list(x=list(relation='free'),
                  y=list(relation='free',
                    draw=FALSE)),
                names.attr,
                par.settings=rasterTheme(),
                ...)

    ## S4 method for signature 'formula,Raster'
    histogram(x, data, dirXY,
                maxpixels = 1e+05,
                strip=TRUE,
                par.settings=rasterTheme(),...)

### Arguments

`x` | A `Raster*` object or a `formula`.
`data` | `NULL` or a `Raster` object.
`layers` | A numeric or character which should indicate the layers to be displayed.
`dirXY` | A direction as a function of the coordinates (see `xyLayer`).
`FUN` | A function to applied to the `z` slot of a `RasterStackBrick` object. The result of this function is used as the grouping variable of the plot.
`nint` | Number of breaks for the histogram. See the documentation of `lattice::histogram` at lattice for details.
`maxpixels` | A numeric, for `sampleRandom`.
`xlab, ylab, main, col` | Arguments for `histogram`.
`names.attr` | Character or expression, names to use in each panel. If missing its default value is the result of `names(x)` (after subsetting the layers to be displayed).
`between, as.table, scales, strip, par.settings` | Graphical parameters of `lattice`. See `lattice::xyplot` for details.
`...` | Additional arguments for `lattice::histogram`

### Note

If you need different breakpoints in each panel, set `breaks` explicitely with `NULL`, a numeric or a character (for example, 'Sturges'; see `hist` for details)

### Author(s)

Oscar Perpiñán Lamigueiro

### See Also

`histogram`,`xscale.raster`, `yscale.raster`, `rasterTheme`

### Examples

    f <- system.file("external/test.grd", package="raster")
    r <- raster(f)
    histogram(r)
    s <- stack(r, r+500, r-500)
    ## Same breakpoints across panels
    histogram(s)
    ## Each panel with different breakpoints
    histogram(s, breaks=NULL)
    histogram(s, breaks='Sturges')
    histogram(s, breaks=30)

    ## Not run:
    ##Solar irradiation data from CMSAF http://dx.doi.org/10.5676/EUM_SAF_CM/RAD_MVIRI/V001
    old <- setwd(tempdir())
    download.file('https://raw.github.com/oscarperpinan/spacetime-vis/master/data/SISmm2008_CMSAF.zip',
       'SISmm2008_CMSAF.zip', method='wget')
    unzip('SISmm2008_CMSAF.zip')

    listFich <- dir(pattern='\.nc')
    stackSIS <- stack(listFich)
    stackSIS <- stackSIS*24 ##from irradiance (W/m2) to irradiation Wh/m2

    idx <- seq(as.Date('2008-01-15'), as.Date('2008-12-15'), 'month')

    SISmm <- setZ(stackSIS, idx)
    names(SISmm) <- month.abb

    histogram(SISmm)
    histogram(SISmm, FUN=as.yearqtr)

    ## With the formula interface you can create histograms for a set of variables
    histogram(~ Jan + Dec, data=SISmm)
    ## Or use the coordinates for generating zonal histograms.
    ## For example, five histograms for each latitude zone
    histogram(~Jan|cut(y, 5), data=SISmm)
    ## More sophisticated bands can be defined using the dirXY argument
    histogram(~Jan|cut(dirXY, 5), dirXY = x^2 + y^2, data=SISmm)

    setwd(old)

    ## End(Not run)

    ## Not run:
    ##http://neo.sci.gsfc.nasa.gov/Search.html?group=64
    pop <- raster('875430rgb-167772161.0.FLOAT.TIFF')
    pop[pop==99999] <- NA
    levelplot(pop, zscaleLog=10, par.settings=BTCTheme,
              panel=panel.levelplot.raster, interpolate=TRUE)

    ##http://neo.sci.gsfc.nasa.gov/Search.html?group=20
    landClass <- raster('241243rgb-167772161.0.TIFF')
    landClass[landClass==254] <- NA

    s <- stack(pop, landClass)
    names(s) <- c('pop', 'landClass')

    histogram(~asinh(pop)|landClass, data=s,
                scales=list(relation='free'),
                strip=strip.custom(strip.levels=TRUE))

    ## End(Not run)

[Package rasterVis version 0.44 Index]