EVOLUTION-MANAGER
Edit File: plot.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Plot a Raster* object</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for plot {raster}"><tr><td>plot {raster}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Plot a Raster* object</h2> <h3>Description</h3> <p>Plot (that is, make a map of) the values of a Raster* object, or make a scatterplot of their values. </p> <p>Points, lines, and polygons can be drawn on top of a map using <code>plot(..., add=TRUE)</code>, or with functions like <code>points, lines, polygons</code> </p> <p>See the <code>rasterVis</code> package for more advanced (trellis/lattice) plotting of Raster* objects. </p> <h3>Usage</h3> <pre> ## S4 method for signature 'Raster,ANY' plot(x, y, maxpixels=500000, col, alpha=NULL, colNA=NA, add=FALSE, ext=NULL, useRaster=TRUE, interpolate=FALSE, addfun=NULL, nc, nr, maxnl=16, main, npretty=0, ...) ## S4 method for signature 'Raster,Raster' plot(x, y, maxpixels=100000, cex, xlab, ylab, nc, nr, maxnl=16, main, add=FALSE, gridded=FALSE, ncol=25, nrow=25, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>Raster* object</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>If <code>x</code> is a RasterStack or RasterBrick: integer, character (layer name(s)), or missing to select which layer(s) to plot. If missing, all RasterLayers in the RasterStack will be plotted (up to a maximum of 16). Or another Raster* object of the same extent and resolution, to produce a scatter plot of the cell values. </p> </td></tr> <tr valign="top"><td><code>maxpixels</code></td> <td> <p>integer > 0. Maximum number of cells to use for the plot. If <code>maxpixels < ncell(x)</code>, <code>sampleRegular</code> is used before plotting. If <code>gridded=TRUE</code> maxpixels may be ignored to get a larger sample</p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>A color palette, i.e. a vector of n contiguous colors generated by functions like <a href="../../grDevices/html/palettes.html">rainbow</a>, <a href="../../grDevices/html/palettes.html">heat.colors</a>, <a href="../../grDevices/html/palettes.html">topo.colors</a>, <a href="../../sp/html/bpy.colors.html">bpy.colors</a> or one or your own making, perhaps using <code><a href="../../grDevices/html/colorRamp.html">colorRampPalette</a></code>. If none is provided, <code>rev(terrain.colors(255))</code> is used unless <code>x</code> has a 'color table'</p> </td></tr> <tr valign="top"><td><code>alpha</code></td> <td> <p>Number between 0 and 1 to set transparency. 0 is entirely transparent, 1 is not transparent (NULL is equivalent to 1)</p> </td></tr> <tr valign="top"><td><code>colNA</code></td> <td> <p>The color to use for the background (default is transparent)</p> </td></tr> <tr valign="top"><td><code>add</code></td> <td> <p>Logical. Add to current plot?</p> </td></tr> <tr valign="top"><td><code>ext</code></td> <td> <p>An extent object to zoom in a region (see also <code><a href="zoom.html">zoom</a></code> and <code><a href="crop.html">crop</a>(x, <a href="drawExtent.html">drawExtent</a>())</code></p> </td></tr> <tr valign="top"><td><code>useRaster</code></td> <td> <p>If <code>TRUE</code>, 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 (see note)</p> </td></tr> <tr valign="top"><td><code>interpolate</code></td> <td> <p>Logical. Should the image be interpolated (smoothed)? Only used when <code>useRaster = TRUE</code></p> </td></tr> <tr valign="top"><td><code>addfun</code></td> <td> <p>Function to add 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.</p> </td></tr> <tr valign="top"><td><code>npretty</code></td> <td> <p>integer. Number of decimals for <a href="../../base/html/pretty.html">pretty</a> lables on the axes</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Graphical parameters. Any argument that can be passed to <code><a href="../../fields/html/image.plot.html">image.plot</a></code> and to base <code>plot</code>, such as axes=FALSE, main='title', ylab='latitude'</p> </td></tr> <tr valign="top"><td><code>xlab</code></td> <td> <p>Optional. x-axis label)</p> </td></tr> <tr valign="top"><td><code>ylab</code></td> <td> <p>Optional. y-axis label)</p> </td></tr> <tr valign="top"><td><code>nc</code></td> <td> <p>Optional. The number of columns to divide the plotting device in (when plotting multiple layers in a RasterLayer or RasterBrick object)</p> </td></tr> <tr valign="top"><td><code>nr</code></td> <td> <p>Optional. The number of rows to divide the plotting device in (when plotting multiple layers in a RasterLayer or RasterBrick object)</p> </td></tr> <tr valign="top"><td><code>maxnl</code></td> <td> <p>integer. Maximum number of layers to plot (for a multi-layer object)</p> </td></tr> <tr valign="top"><td><code>main</code></td> <td> <p>character. Main plot title</p> </td></tr> <tr valign="top"><td><code>cex</code></td> <td> <p>Symbol size for scatter plots</p> </td></tr> <tr valign="top"><td><code>gridded</code></td> <td> <p>logical. If <code>TRUE</code> the scatterplot is gridded (counts by cells)</p> </td></tr> <tr valign="top"><td><code>ncol</code></td> <td> <p>integer. Number of columns for gridding</p> </td></tr> <tr valign="top"><td><code>nrow</code></td> <td> <p>integer. Number of rows for gridding</p> </td></tr> </table> <h3>Details</h3> <p>Most of the code for the plot function for a single Raster* object was taken from image.plot (fields package). </p> <p>Raster objects with a color-table (e.g. a graphics file) are plotted according to that color table. </p> <h3>Note</h3> <p>raster uses <code><a href="../../graphics/html/rasterImage.html">rasterImage</a></code> from the graphics package. For unknown reasons this does not work on Windows Server and on a few versions of Windows XP. On that system you may need to use argument <code>useRaster=FALSE</code> to get a plot. </p> <h3>See Also</h3> <p>The <code>rasterVis</code> package has lattice based methods for plotting Raster* objects (like <code><a href="spplot.html">spplot</a></code>) </p> <p>red-green-blue plots (e.g. false color composites) can be made with <code><a href="plotRGB.html">plotRGB</a></code> </p> <p><code><a href="barplot.html">barplot</a></code>, <code><a href="hist.html">hist</a></code>, <code><a href="text.html">text</a></code>, <code><a href="persp.html">persp</a></code>, <code><a href="contour.html">contour</a></code>, <code><a href="pairs.html">pairs</a></code> </p> <h3>Examples</h3> <pre> # RasterLayer r <- raster(nrows=10, ncols=10) r <- setValues(r, 1:ncell(r)) plot(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) plot(r, r2, gridded=TRUE) # Multi-layer object (RasterStack / Brick) s <- stack(r, r2, r/r) plot(s, 2) plot(s) # two objects, different range, one scale: values(r) <- runif(ncell(r)) r2 <- r/2 brks <- seq(0, 1, by=0.1) nb <- length(brks)-1 cols <- rev(terrain.colors(nb)) par(mfrow=c(1,2)) plot(r, breaks=brks, col=cols, lab.breaks=brks, zlim=c(0,1), main='first') plot(r2, breaks=brks, col=cols, lab.breaks=brks, zlim=c(0,1), main='second') # breaks and labels x <- raster(nc=10, nr=10) values(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 the same 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) </pre> <hr /><div style="text-align: center;">[Package <em>raster</em> version 3.3-13 <a href="00Index.html">Index</a>]</div> </body></html>