Learn R Programming

terra (version 1.8-80)

colors: Color table

Description

Get or set color table(s) associated with a SpatRaster. Color tables are used for associating colors with values, for use in mapping (plot).

Usage

# S4 method for SpatRaster
coltab(x)

# S4 method for SpatRaster coltab(x, ..., layer=1)<-value

# S4 method for SpatRaster has.colors(x)

Arguments

Value

data.frame

Examples

Run this code
r <- rast(ncols=3, nrows=2, vals=1:6)
x <- c(r, r)
names(x) <- c("A", "B")

coltb <- data.frame(value=1:6, col=rainbow(6, end=.9))
coltb

plot(r)

has.colors(r)
coltab(r) <- coltb
plot(r)
has.colors(r)

tb <- coltab(r)
class(tb)
dim(tb[[1]])

coltab(x, layer="B") <- coltb

Run the code above in your browser using DataLab