Learn R Programming

raster (version 1.8-3)

spplot: Use spplot or ggplot to plot a Raster* object

Description

These are simple wrapper functions to around spplot (sp package) and ggplot (ggplot2 package), allowing for attractive mapping of Raster objects. For example, with spplot it is easy to map several layers with a single legend for all maps. Note that the function in the raster package is called gplot with a single 'g'. One of the advantages of these wrapper functions is the additioal maxpixels argument to sample large Raster objects for faster drawing.

Usage

gplot(x, ...)

Arguments

x
A Raster* object
...
Additional arguments. See under Details

Methods

spplot(obj, maxpixels=50000, ...) gplot(x, maxpixels=50000, ...) rll{ obj A Raster* object maxpixels Integer. Number of pixels to sample from each layer of large Raster objects ... Any argument that can be passed to spplot or to ggplot }

Details

Most of the code for this function was taken from image.plot (fields package). Raster objects with a color-table (e.g. a graphics file) will be plotted according to the color table.

See Also

plot, plot3D, plotRGB, , persp, contour, pairs, hist

Examples

Run this code
r <- raster(system.file("external/test.grd", package="raster"))
s <- stack(r, r*2)
layerNames(s) <- c('meuse', 'meuse x 2')

spplot(s)

if (require(ggplot2)) {
	theme_set(theme_bw())
	gplot(s) + geom_tile(aes(fill = value)) + facet_wrap(~ variable) +
            scale_fill_gradient(low = 'white', high = 'blue') + coord_equal()
}

Run the code above in your browser using DataLab