Plot the values of a SpatRaster or SpatVector to make a map.
See points, lines or polys to add a SpatVector to an existing map (or use argument add=TRUE).
There is a separate help file for plotting a SpatGraticule or SpatExtent.
methods
## S4 method for signature 'SpatRaster,numeric'plot(x, y=1, col, type=NULL, mar=NULL, legend=TRUE, axes=!add, plg=list(), pax=list(), maxcell=500000, smooth=FALSE, range=NULL, fill_range=FALSE, levels=NULL, all_levels=FALSE, breaks=NULL, breakby="eqint", fun=NULL, colNA=NULL, alpha=NULL, sort=FALSE, decreasing=FALSE, grid=FALSE, ext=NULL, reset=FALSE, add=FALSE, buffer=FALSE, background=NULL, box=axes, clip=TRUE, overview=NULL,...)## S4 method for signature 'SpatRaster,missing'plot(x, y, main, mar=NULL, nc, nr, maxnl=16, maxcell=500000, add=FALSE,...)## S4 method for signature 'SpatRaster,character'plot(x, y,...)## S4 method for signature 'SpatVector,character'plot(x, y, col=NULL, type=NULL, mar=NULL, add=FALSE, legend=TRUE, axes=!add, main="", buffer=TRUE, background=NULL, grid=FALSE, ext=NULL, sort=TRUE, decreasing=FALSE, plg=list(), pax=list(), nr, nc, colNA=NA, alpha=NULL, box=axes, clip=TRUE,...)## S4 method for signature 'SpatVector,numeric'plot(x, y,...)## S4 method for signature 'SpatVector,missing'plot(x, y, values=NULL,...)## S4 method for signature 'SpatVectorCollection,missing'plot(x, y, main, mar=NULL, nc, nr, maxnl=16,...)## S4 method for signature 'SpatVectorCollection,numeric'plot(x, y, main, mar=NULL, ext=NULL,...)
Arguments
x: SpatRaster or SpatVector
y: missing or positive integer or name indicating the layer(s) to be plotted
col: character vector to specify the colors to use. The default is map.pal("viridis", 100). The default can be changed with the terra.pal option. For example: options(terra.pal=terrain.colors(10)). If x is a SpatRaster, it can also be a data.frame with two columns (value, color) to get a "classes" type legend or with three columns (from, to, color) to get an "interval" type legend
type: character. Type of map/legend. One of "continuous", "classes", or "interval". If not specified, the type is chosen based on the data
mar: numeric vector of length 4 to set the margins of the plot (to make space for the legend). The default is (3.1, 3.1, 2.1, 7.1) for a single plot with a legend and (3.1, 3.1, 2.1, 2.1) otherwise. The default for a RGB raster is 0. Use mar=NA to not set the margins
legend: logical or character. If not FALSE a legend is drawn. The character value can be used to indicate where the legend is to be drawn. For example "topright" or "bottomleft". Use plg for more refined placement. Not supported for continuous legends (the default for raster data)
axes: logical. Draw axes?
buffer: logical. If TRUE the plotting area is made slightly larger than the extent of x
background: background color. Default is no color (white)
box: logical. Should a box be drawn around the map?
clip: logical. Should the axes be clipped to the extent of x?
overview: logical. Should "overviews" be used for fast rendering? This can result in much faster plotting of raster files that have overviews (e.g. "COG" format) and are accessed over a http connection. However, these overviews generally show aggregate values, thus reducing the range of the actual values. If NULL, the argument is set to TRUE for rasters that are accessed over http and FALSE in other cases
plg: list with parameters for drawing the legend. For the classes and interval type legend see the arguments for legend. For example x and y can be used to place the legend. You can also use keywords such as "topleft" and "bottomright" to place the legend at these locations inside the map rectangle.
Some of these do not apply to a continuous legend, or they behave a little differently. For example, only the placement keywords "left", "right", "top", and "bottom" are recognized; and when using these keywords, the legend is placed outside of the map rectangle. Additional parameters for continuous legends include:
digits to set the number of digits to print after the decimal point. size to change the height and/or width; the defaults are c(1,1), negative values for size flip the order of the legend.
at to set the location of the tic-marks
tic One of these partially matched values: "through", "in", "out", or "none", to choose a tic-mark placement/length that is different from the default "through and out".
pax: list with parameters for drawing axes. See the arguments for axis. Arguments side, tick and lab can be used to indicate for which of the four axes to draw a line (side), tick-mark, and/or the tick-mark labels. The default is c(1:4) for side and 1:2 for the other two. If side is changed the other two default to that value. Logical argument retro can be used to use a sexagesimal notation for the labels (degrees/minutes/hemisphere) instead of the standard decimal notation
maxcell: positive integer. Maximum number of cells to use for the plot
smooth: logical. If TRUE the cell values are smoothed (only if a continuous legend is used)
range: numeric. minimum and maximum values to be used for the continuous legend. You can use NA for one of these to only set the minimum or maximum value
fill_range: logical. If TRUE, values outside of range get the colors of the extreme values; otherwise they get colored as NA
levels: character. labels for the legend when type="classes"
all_levels: logical. If TRUE, the legend shows all levels of a categorical raster, even if they are not present in the data
breaks: numeric. Either a single number to indicate the number of breaks desired, or the actual breaks. When providing this argument, the default legend becomes "interval"
breakby: character or function. Either "eqint" for equal interval breaks, "cases" for equal quantile breaks. If a function is supplied, it should take a single argument (a vector of values) and create groups
fun: function to be called after plotting each SpatRaster layer to add something to each map (such as text, legend, lines). For example, with SpatVector v, you could do fun=function() lines(v). The function may have one argument, representing the layer that is plotted (1 to the number of layers)
colNA: character. color for the NA values
alpha: Either a single numeric between 0 and 1 to set the transparency for all colors (0 is transparent, 1 is opaque) or a SpatRaster with values between 0 and 1 to set the transparency by cell. To set the transparency for a given color, set it to the colors directly
sort: logical. If TRUE legends with categorical values are sorted. If x is a SpatVector you can also supply a vector of the unique values, in the order in which you want them to appear in the legend
decreasing: logical. If TRUE, legends are sorted in decreasing order
grid: logical. If TRUE grid lines are drawn. Their properties such as type and color can be set with the pax argument
nc: positive integer. Optional. The number of columns to divide the plotting device in (when plotting multiple layers)
nr: positive integer. Optional. The number of rows to divide the plotting device in (when plotting multiple layers)
main: character. Main plot titles (one for each layer to be plotted). You can use arguments cex.main, font.main, col.main to change the appearance; and loc.main to change the location of the main title (either two coordinates, or a character value such as "topleft")
maxnl: positive integer. Maximum number of layers to plot (for a multi-layer object)
add: logical. If TRUE add the object to the current plot
ext: SpatExtent. Can be use instead of xlim and ylim to set the extent of the plot
reset: logical. If TRUE add the margins (see argument mar) are reset to what they were before calling plot; doing so may affect the display of additional objects that are added to the map (e.g. with lines)
values: Either a vector with values to be used for plotting or a two-column data.frame, where the first column matches a variable in x and the second column has the values to be plotted
...: arguments passed to plot("SpatRaster", "numeric") and additional graphical arguments