plotRGB: Red-Green-Blue plot of a multi-layered SpatRaster

plotRGBR Documentation

Red-Green-Blue plot of a multi-layered SpatRaster

Description

Make a Red-Green-Blue plot based on three layers in a SpatRaster. The layers (sometimes referred to as "bands" because they may represent different bandwidths in the electromagnetic spectrum) are combined such that they represent the red, green and blue channel. This function can be used to make "true" (or "false") color images from Landsat and other multi-spectral satellite images.

Note that the margins of the plot are set to zero (no axes or titles are visible) but can be set with the mar argument.

An alternative way to plot RGB images is to first use colorize to create a single layer SpatRaster with a color-table and then use plot.

Usage

## S4 method for signature 'SpatRaster'
plotRGB(x, r=1, g=2, b=3, a=NULL, scale, maxcell=500000, mar=0, 
		stretch=NULL, ext=NULL, smooth=FALSE, colNA="white", alpha, bgalpha, 
		addfun=NULL, zlim=NULL, zlimcol=NULL, axes=FALSE, xlab="", ylab="", 
		asp=NULL, add=FALSE, xlim, ylim,...)

Arguments

x

SpatRaster

r

integer. Index of the Red channel, between 1 and nlyr(x)

g

integer. Index of the Green channel, between 1 and nlyr(x)

b

integer. Index of the Blue channel, between 1 and nlyr(x)

a

integer. Index of the alpha (transparancy) channel, between 1 and nlyr(x). If not NULL, argument alpha is ignored

scale

integer. Maximum (possible) value in the three channels. Defaults to 255 or to the maximum value of x if that is known and larger than 255

maxcell

integer > 0. Maximum number of pixels to use

mar

numeric vector recycled to length 4 to set the margins of the plot. Use mar=NULL or mar=NA to not set the margins

stretch

character. Option to stretch the values to increase contrast: "lin" (linear) or "hist" (histogram)

ext

An SpatExtent object to zoom in to a region of interest (see draw)

smooth

logical. If TRUE, smooth the image when drawing to get the appearance of a higher spatial resolution

colNA

color for the background (NA values)

alpha

transparency. Integer between 0 (transparent) and 255 (opaque)

bgalpha

Background transparency. Integer between 0 (transparent) and 255 (opaque)

addfun

Function to add additional items such as points or polygons to the plot (map). See plot

zlim

numeric vector of length 2. Range of values to plot (optional)

zlimcol

If NULL the values outside the range of zlim get the color of the extremes of the range. If zlimcol has any other value, the values outside the zlim range get the color of NA values (see colNA)

axes

logical. If TRUE axes are drawn (and arguments such as main="title" will be honored)

xlab

character. Label of x-axis

ylab

character. Label of y-axis

asp

numeric. Aspect (ratio of x and y. If NULL, and appropriate value is computed to match data for the longitude/latitude coordinate reference system, and 1 for planar coordinate reference systems

add

logical. If TRUE add values to current plot

xlim

numeric. min and max values to set the extent of the x-axis

ylim

numeric. min and max values to set the extent of the y-axis

...

graphical parameters as in plot or rasterImage

See Also

plot, colorize, RGB

Examples

b <- rast(system.file("ex/logo.tif", package="terra"))   
plotRGB(b)
plotRGB(b, mar=c(2,2,2,2))
plotRGB(b, 3, 2, 1)

b[1000:2000] <- NA
plotRGB(b, 3, 2, 1, stretch='hist')

terra documentation built on Sept. 11, 2022, 1:06 a.m.