Learn R Programming

rasterVis (version 0.51.6)

densityplot-methods: Density plots for Raster objects.

Description

Draw kernel density plots (with lattice) of Raster objects.

Usage

# S4 method for Raster,missing
densityplot(x, data=NULL, layers, FUN,
            maxpixels = 1e+05,
            xlab='', ylab='', main='',
            par.settings=rasterTheme(),
            draw.labels = TRUE,
            auto.key = list(space = "right"),
            att = 1,
            ...)

# S4 method for formula,Raster densityplot(x, data, dirXY, maxpixels = 1e+05, xscale.components=xscale.raster, yscale.components=yscale.raster, auto.key = list(space = 'right'), par.settings=rasterTheme(),...)

# S4 method for SpatRaster,missing densityplot(x, data=NULL, layers, FUN, maxpixels = 1e+05, xlab='', ylab='', main='', par.settings=rasterTheme(), draw.labels = TRUE, auto.key = list(space = "right"), att = 1, ...)

# S4 method for formula,SpatRaster densityplot(x, data, dirXY, maxpixels = 1e+05, xscale.components=xscale.raster, yscale.components=yscale.raster, auto.key = list(space = 'right'), par.settings=rasterTheme(),...)

Arguments

x

A Raster* object, a SpatRaster object, or a formula.

data

NULL, a Raster object, or a SpatRaster 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 or to the time index of a SpatRaster object. The result of this function is used as the grouping variable of the plot.

maxpixels

A numeric, for sampleRandom or spatSample.

draw.labels

Logical. If TRUE (default), labels are displayed over the maximum value of each layer. If FALSE, a key is displayed according to the auto.key argument.

xlab, ylab, main, xscale.components, yscale.components, par.settings, auto.key

Arguments for densityplot.

att

Integer or character to choose which variable (column) in the RAT table should be used.

...

Additional arguments for densityplot

Author

Oscar Perpiñán Lamigueiro

See Also

lattice:densityplot(),xscale.raster, yscale.raster, rasterTheme

Examples

Run this code
library(raster)
library(terra)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)
densityplot(r)
s <- stack(r, r+500, r-500)
## With labels
densityplot(s)
## With a key
densityplot(s, draw.labels = FALSE)

if (FALSE) {
library(zoo)

dataURL <- "https://raw.github.com/oscarperpinan/bookvis/master/data/"

##Solar irradiation data from CMSAF http://dx.doi.org/10.5676/EUM_SAF_CM/RAD_MVIRI/V001
old <- setwd(tempdir())
download.file(paste0(dataURL, "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
setwd(old)

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

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

densityplot(SISmm)
##FUN applies to z if not NULL
densityplot(SISmm, FUN=as.yearqtr)
}
if (FALSE) {
##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')

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

Run the code above in your browser using DataLab