utils_color: Color utilities

Description Usage Arguments Value Examples

Description

From given values, generate colors for plotting points or surfaces.

Usage

1
2
3
colvec(x, n = 99, pal, zeroctr = FALSE, ...)

surfcol(x, ngrid, pal, ...)

Arguments

x

vector of values to evaluate

n

number of unique colors to be used in the palette

pal

optional specification for a color palette; defaults to viridis::inferno palette if missing

zeroctr

logical, should the color scale diverge to be symmetrical around zero?

...

further arguments passed to other methods

ngrid

number of grid cells in the matrix of values plotted in persp

Value

Vector or matrix of color values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# generate data
x <- seq(-1.95, 1.95, length = 30)
y <- seq(-1.95, 1.95, length = 35)
z <- outer(x, y, function(a, b) a*b^2)

# color surface of perspective plot by 'z' value
ngrid <- prod(dim(z))
f     <- surfcol(z, ngrid=ngrid, alpha=0.8)
persp(x, y, z, col=f, phi=30, theta=-30)

# color points by numeric values
plot(x, y[1:30], col=colvec(x))

# color points by factor values
trmt <- gl(3, 10, labels = c('Q', 'R', 'S'))
plot(x, y[1:30], col=colvec(rev(trmt)))

# divergent colors centered on zero
set.seed(21)
x <- (rbeta(99, 0.5, 1) - 0.15) * 100
par(mfrow=c(1,3))
plot(x, col=colvec(x))
plot(x, col=colvec(x, zeroctr=TRUE))
plot(x, col=colvec(pseudo_log(x), zeroctr=TRUE))
par(mfrow=c(1,1))

phytomosaic/ecole documentation built on Jan. 2, 2022, 11:24 p.m.