add.alpha: Add alpha (transparency) to a color

Description Usage Arguments Details See Also Examples

View source: R/add.alpha.R

Description

Friendly way to change the transparency of a color of vector of colors that are specified by name.

Usage

1
add.alpha(col, alpha = 1)

Arguments

col

a color, specified as in colors, or in output format of rgb

alpha

numeric vector w/ value(s) between 0 (transparent) and 1 (opaque)

Details

Pretty sure I got the code (or inspiration) here. This function is simple (the code is just 1 line), but it is quick and convenient.

See Also

See rgb, colors, colorRampPalette, adjustcolor for base functions handling colors. See rbLib-package for package overview.

Examples

1
2
3
4
5
6
7
8
9
N <- 10
blues <- add.alpha("blue", seq(0.1,1, length.out=N))
plot(1:N, col=blues, pch=19)
b2r <- colorRampPalette

ba <- add.alpha("blue", alpha=0.25)
ra <- add.alpha("red", alpha=1)
cols <- colorRampPalette(c(ba, ra), alpha=TRUE)(N)
plot(1:N, col=cols, pch=19)

rBatt/rbLib documentation built on May 26, 2019, 7:45 p.m.