Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

plotRGB

Red-Green-Blue plot of a multi-layered Raster object


Description

Make a Red-Green-Blue plot based on three layers (in a RasterBrick or RasterStack). Three 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-band satellite images.

Usage

## S4 method for signature 'RasterStackBrick'
plotRGB(x, r=1, g=2, b=3, scale, maxpixels=500000, stretch=NULL, 
ext=NULL, interpolate=FALSE, colNA='white', alpha, bgalpha, addfun=NULL, zlim=NULL, 
zlimcol=NULL, axes=FALSE, xlab='', ylab='', asp=NULL, add=FALSE, margins=FALSE, ...)

Arguments

x

RasterBrick or RasterStack

r

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

g

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

b

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

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

maxpixels

integer > 0. Maximum number of pixels to use

stretch

character. Option to stretch the values to increase the contrast of the image: "lin" or "hist"

ext

An Extent object to zoom in to a region of interest (see drawExtent)

interpolate

logical. If TRUE, interpolate the image when drawing

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

margins

logical. If TRUE standard whitespace margins are used. If FALSE, graphics::par(plt=c(0,1,0,1)) is used

...

graphical parameters as in plot or rasterImage

Author(s)

Robert J. Hijmans; stretch option based on functions by Josh Gray

See Also

Examples

b <- brick(system.file("external/rlogo.grd", package="raster"))
plotRGB(b)
plotRGB(b, 3, 2, 1)
plotRGB(b, 3, 2, 1, stretch='hist')

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.