Description
Level and contour plots of Raster objects with lattice
methods and marginal plots with grid
objects.
Usage
## S4 method for signature 'Raster,missing' levelplot(x, data=NULL, layers, margin=!(any(is.factor(x))), FUN.margin=mean, maxpixels=1e5, par.settings=rasterTheme(), between=list(x=0.5, y=0.2), as.table=TRUE, xlab='', ylab='', main='', names.attr, scales=list(), scales.margin=NULL, xscale.components=xscale.raster, yscale.components=yscale.raster, zscaleLog=NULL, colorkey=list(space='right'), panel=panel.levelplot, contour=FALSE, region=TRUE, labels=FALSE, ...) ## S4 method for signature 'Raster,missing' contourplot(x, data=NULL, layers, ...)
Arguments
x |
A Raster object. |
data |
Not used. |
layers |
A numeric or character which should indicate the layers to be displayed. |
margin |
logical, if TRUE a marginal plot of the FUN.margin function to each coordinate will be displayed. |
FUN.margin |
A function to be applied to each coordinate. |
scales.margin |
A list with components x and y . Each of these components is a numeric vector of length 2 defining the range for each marginal plot. If scales.margin=NULL the range is internally computed. |
maxpixels |
A numeric, for sampleRegular . |
xlab, ylab, main |
Arguments for levelplot . |
names.attr |
Character, names to use in each panel. If missing its default value is the result of names(x) (after subsetting the layers to be displayed). |
xscale.components, yscale.components |
See xscale.raster and yscale.raster . |
between, as.table, par.settings, scales, colorkey, panel, contour, region, labels |
Graphical parameters of lattice . See xyplot for details. |
zscaleLog |
Controls whether the Raster* will be log transformed before being passed to the panel function. Defaults to ???NULL???, in which case the Raster* is not transformed. Other possible values are any number that works as a base for taking logarithm, ???TRUE??? (which is equivalent to 10), and ???”e”??? (for the natural logarithm). As a side effect, the colorkey is labeled differently. |
... |
Additional arguments for levelplot |
Details
The result of the levelplot
method is similar to the spplot
method for Raster
objects defined in the raster
package. However, this method does not use the spplot
of the sp
package and, therefore, no conversion between classes is needed.
The contourplot
method is a wrapper for levelplot
with the next additional default settings: cuts=7
, labels=TRUE
, contour
=TRUE,pretty
=TRUE, region=TRUE
and colorkey=TRUE
(see the help of contourplot
for details.)
levelplot
displays categorical data with a convenient legend. You should use ratify
to define a layer as a categorical variable. It is able to display multilayer categorical rasters only if they share the same RAT (Raster Attribute Table). levelplot
is not able to display multilayer rasters with factor and numeric layers. See ratify
and the examples below for details.
Author(s)
Oscar Perpi????n Lamigueiro
See Also
spplot
, levelplot
Examples
f <- system.file("external/test.grd", package="raster") r <- raster(f) levelplot(r) ## With subticks levelplot(r, xscale.components=xscale.raster.subticks, yscale.components=yscale.raster.subticks) levelplot(r, xscale.components=xscale.raster.subticks, yscale.components=yscale.raster.subticks, scales=list(x=list(rot=30, cex=0.8))) ## defining the scales for the marginal plot levelplot(r, scales.margin=list(x=c(100, 600), y=c(100, 1000))) ## if a component of the list is null, it is internally calculated levelplot(r, scales.margin=list(x=c(100, 1000))) ## log-scale levelplot(r^2, zscaleLog=TRUE, contour=TRUE) s <- stack(r, r+500, r-500) levelplot(s, contour=TRUE) contourplot(s, labels=list(cex=0.4), cuts=12) levelplot(s, names.attr=c('R', 'R + 500', 'R - 500')) ## Add a layer of sampling points ## and change the theme pts <- sampleRandom(r, size=20, sp=TRUE) ## Using +.trellis and layer from latticeExtra levelplot(r, par.settings = BTCTheme) + layer(sp.points(pts, col = 'red')) contourplot(r, labels = FALSE) + layer(sp.points(pts, col = 'red')) ## or with a custom panel function levelplot(r, par.settings=BTCTheme, panel=function(...){ panel.levelplot(...) sp.points(pts, col='red') }) ## Categorical data r <- raster(nrow=10, ncol=10) r[] = 1 r[51:100] = 3 r[3:6, 1:5] = 5 r <- ratify(r) rat <- levels(r)[[1]] rat$landcover <- c('Pine', 'Oak', 'Meadow') levels(r) <- rat r levelplot(r, col.regions=c('palegreen', 'midnightblue', 'indianred1')) r2 <- raster(r) r2[] = 3 r2[51:100] = 1 r2[3:6, 1:5] = 5 r3 <- init(r, function(n)sample(c(1, 3, 5), n, replace=TRUE)) ## Multilayer categorical Raster* are displayed only if their RATs are the same levels(r2) <- levels(r3) <- levels(r) s <- stack(r, r2, r3) names(s) <- c('A', 'B', 'C') levelplot(s) ## Not run: ##Solar irradiation data from CMSAF ##Data available from http://www.box.net/shared/rl51y1t9sldxk54ogd44 old <- getwd() ##change to your folder... setwd('CMSAF') listFich <- dir(pattern='2008') 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 levelplot(SISmm) levelplot(SISmm, layers=1, FUN.margin=median, contour=TRUE) ## End(Not run)
Results
R version 2.15.3 (2013-03-01) -- "Security Blanket" Copyright (C) 2013 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-unknown-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(rasterVis) Loading required package: raster Loading required package: sp Loading required package: lattice Loading required package: latticeExtra Loading required package: RColorBrewer Loading required package: hexbin Loading required package: grid > png(filename="/home/oogasawa/snapshot/RGM3/R_CC/result/rasterVis/levelplot-methods.Rd_%03d_medium.png", width=480, height=480) > ### Name: levelplot-methods > ### Title: Level and contour plots of Raster objects. > ### Aliases: levelplot contourplot levelplot,Raster,missing-method > ### contourplot,Raster,missing-method > ### Keywords: methods spatial > > ### ** Examples > > f <- system.file("external/test.grd", package="raster") > r <- raster(f) > levelplot(r) > > ## With subticks > levelplot(r, xscale.components=xscale.raster.subticks, + yscale.components=yscale.raster.subticks) > > levelplot(r, xscale.components=xscale.raster.subticks, + yscale.components=yscale.raster.subticks, + scales=list(x=list(rot=30, cex=0.8))) > > ## defining the scales for the marginal plot > levelplot(r, scales.margin=list(x=c(100, 600), y=c(100, 1000))) > ## if a component of the list is null, it is internally calculated > levelplot(r, scales.margin=list(x=c(100, 1000))) > > ## log-scale > levelplot(r^2, zscaleLog=TRUE, contour=TRUE) > > s <- stack(r, r+500, r-500) > levelplot(s, contour=TRUE) > contourplot(s, labels=list(cex=0.4), cuts=12) > > levelplot(s, names.attr=c('R', 'R + 500', 'R - 500')) > > ## Add a layer of sampling points > ## and change the theme > pts <- sampleRandom(r, size=20, sp=TRUE) > > ## Using +.trellis and layer from latticeExtra > levelplot(r, par.settings = BTCTheme) + layer(sp.points(pts, col = 'red')) > contourplot(r, labels = FALSE) + layer(sp.points(pts, col = 'red')) > > ## or with a custom panel function > levelplot(r, par.settings=BTCTheme, + panel=function(...){ + panel.levelplot(...) + sp.points(pts, col='red') + }) > > > ## Categorical data > r <- raster(nrow=10, ncol=10) > r[] = 1 > r[51:100] = 3 > r[3:6, 1:5] = 5 > r <- ratify(r) > > rat <- levels(r)[[1]] > rat$landcover <- c('Pine', 'Oak', 'Meadow') > levels(r) <- rat > r class : RasterLayer dimensions : 10, 10, 100 (nrow, ncol, ncell) resolution : 36, 18 (x, y) extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 data source : in memory names : layer values : 1, 5 (min, max) attributes : ID landcover 1 Pine 3 Oak 5 Meadow > > levelplot(r, col.regions=c('palegreen', 'midnightblue', 'indianred1')) > > r2 <- raster(r) > r2[] = 3 > r2[51:100] = 1 > r2[3:6, 1:5] = 5 > > r3 <- init(r, function(n)sample(c(1, 3, 5), n, replace=TRUE)) > > ## Multilayer categorical Raster* are displayed only if their RATs are the same > levels(r2) <- levels(r3) <- levels(r) > > s <- stack(r, r2, r3) > names(s) <- c('A', 'B', 'C') > > levelplot(s) > > > ## Not run: > ##D ##Solar irradiation data from CMSAF > ##D ##Data available from http://www.box.net/shared/rl51y1t9sldxk54ogd44 > ##D > ##D old <- getwd() > ##D ##change to your folder... > ##D setwd('CMSAF') > ##D listFich <- dir(pattern='2008') > ##D stackSIS <- stack(listFich) > ##D stackSIS <- stackSIS*24 ##from irradiance (W/m2) to irradiation Wh/m2 > ##D setwd(old) > ##D > ##D idx <- seq(as.Date('2008-01-15'), as.Date('2008-12-15'), 'month') > ##D > ##D SISmm <- setZ(stackSIS, idx) > ##D names(SISmm) <- month.abb > ##D > ##D levelplot(SISmm) > ##D > ##D levelplot(SISmm, layers=1, FUN.margin=median, contour=TRUE) > ## End(Not run) > > > > > dev.off() null device 1 >
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |