Learn R Programming

terra (version 1.8-80)

RGB: Layers representing colors

Description

With RGB you can get or set the layers to be used as Red, Green and Blue when plotting a SpatRaster. Currently, a benefit of this is that plot will send the object to plotRGB. You can also associated the layers with another color space (HSV, HSI or HSL)

With colorize you can convert a three-layer RGB SpatRaster into other color spaces. You can also convert it into a single-layer SpatRaster with a color-table.

Usage

# S4 method for SpatRaster
RGB(x, value=NULL, type="rgb")

# S4 method for SpatRaster RGB(x, ..., type="rgb")<-value

# S4 method for SpatRaster colorize(x, to="hsv", alpha=FALSE, stretch=NULL, grays=FALSE, NAzero=FALSE, filename="", overwrite=FALSE, ...)

# S4 method for SpatRaster has.RGB(x, strict=TRUE)

Arguments

See Also

set.RGB

Examples

Run this code
r <- rast(system.file("ex/logo.tif", package="terra"))   
RGB(r)
plot(r)
has.RGB(r)
RGB(r) <- NULL
has.RGB(r)
plot(r)
RGB(r) <- c(3,1,2)
# same as 
# r <- RGB(r, c(3,1,2))

plot(r)

RGB(r) <- 1:3
x <- colorize(r, "col")
y <- colorize(r, "hsv")
z <- colorize(y, "rgb")

Run the code above in your browser using DataLab