
plot(..., add=TRUE)
, or functions like points, lines, polygons
text
plots a textual (rather than color) representation of values of the cells on top of the cells.plot(x, col=rev(terrain.colors(25)), maxpixels=100000, axes = TRUE, xlab="", ylab="", alpha=1, useRaster=TRUE, ...)
x
- RasterLayer object
col
- A color palette, i.e. a vector of n contiguous colors such as rainbow, heat.colors, and topo.colors, or one or your own making, perhaps using colorRampPalette
maxpixels
- Maximum number of pixels used for the map
alpha
- Number between 0 and 1 to set transparancy. 0 is entirely transparant, 1 is not transparant
useRaster
- If TRUE
, the rasterImage function is used for plotting. Otherwise the image function is used. This can be useful if rasterImage does not work well on your system
...
- Any argument that can be passed to image.plot
and to plot
If x
has a 'Color table', the default all to plot
is:
plot(x, maxpixels=500000, ext=NULL, interpolate=FALSE, axes=FALSE, xlab="", ylab="", ...)
ext
An extent object to zoom in a region
interpolate
Logical. Should the image be interpolated?
axes
Logical. Should axes be drawn?
addfun
Function. functions adding additional items such as points or polygons to the plot (map). Typically containing statements like "points(xy); plot(polygons, add=TRUE)". This is particularly useful to add something to each map when plotting a multi-layer Raster* object.
...
Graphical parameters
}
x=RasterStack or RasterBrick, y=numeric or missing
plot(x, col=rev(terrain.colors(25)), subsample=TRUE, maxpixels=100000, alpha=1, axes=TRUE, xlab="", ylab="", ...)
x
a RasterStack or RasterBrick object
y
The index of a RasterLayer in a RasterStack to be plotted. Either a single number between 1 and nlayers(rstack), a vector of numbers, or missing. If y is missing, all RasterLayers in the RasterStack will be plotted (up to a maximum of 16).
other arguments
See above
}
x=Raster, y=Raster
Produces a scatter plot of the values of x against those of y.
plot(x, y, maxpixels=100000, cex=0.1, ...)
x
a RasterLayer object
y
a RasterLayer object
maxpixels
Maximum number of pixels in the map display
cex
point size
...
Any argument that can be passed to graphics::plot
}
x=Extent, y="ANY"
Draws the (rectangular) bounding box of a raster object.
plot(ext)
ext
a Extent object
}spplot, plotRGB, persp, contour, pairs, hist
The rasterVis package has more advanced plotting methods for Raster* objects.# RasterLayer
r <- raster(nrows=10, ncols=10)
r <- setValues(r, 1:ncell(r))
plot(r)
text(r)
e <- extent(r)
plot(e, add=TRUE, col='red', lwd=4)
e <- e / 2
plot(e, add=TRUE, col='red')
# Scatterplot of 2 RasterLayers
r2 <- sqrt(r)
plot(r, r2)
# Multi-layer object (RasterStack / Brick)
s <- stack(r, r2, r/r)
plot(s, 2)
plot(s)
# two objects, different range, one scale:
r[] <- runif(ncell(r))
r2 <- r/2
brks <- seq(0, 1, by=0.1)
nb <- length(brks)-1
par(mfrow=c(1,2))
plot(r, breaks=brks, col=rev(terrain.colors(nb)), lab.breaks=brks, zlim=c(0,1))
plot(r2, breaks=brks, col=rev(terrain.colors(nb)), lab.breaks=brks, zlim=c(0,1))
# breaks and labels
x <- raster(nc=10, nr=10)
x[] <- runif(ncell(x))
brk <- c(0, 0.25, 0.75, 1)
arg <- list(at=c(0.12,0.5,0.87), labels=c("Low","Med.","High"))
plot(x, col=terrain.colors(3), breaks=brk)
plot(x, col=terrain.colors(3), breaks=brk, axis.args=arg)
par(mfrow=c(1,1))
# color ramp
plot(x, col=colorRampPalette(c("red", "white", "blue"))(255))
# adding random points to the map
xy <- cbind(-180 + runif(10) * 360, -90 + runif(10) * 180)
points(xy, pch=3, cex=5)
# for SpatialPolygons do
# plot(pols, add=TRUE)
# adding random points to each map of each layer of a RasterStack
fun <- function() {
points(xy, cex=2)
points(xy, pch=3, col='red')
}
plot(s, addfun=fun)
Run the code above in your browser using DataLab