Learn R Programming

marmap (version 1.0.10)

col2alpha: Adds alpha transparency to a (vector of) color(s)

Description

Adds transparency to a color or a vector of colors by specifying one or several alpha values.

Usage

col2alpha(color,alpha = 0.5)

Value

A (vector) of color code(s).

Arguments

color

a (vector of) color codes or names

alpha

a value (or vector of values) between 0 (full transparency) and 1 (no transparency).

Author

Benoit Simon-Bouhet

Details

When the size of color and alpha vectors are different, alpha values are recycled.

Examples

Run this code
# Generate random data
dat <- rnorm(4000)

# plot with plain color for points
plot(dat,pch=19,col="red")

# Add some transparency to get a better idea of density
plot(dat,pch=19,col=col2alpha("red",.3))

# Same color for all points but with increasing alpha (decreasing transparency)
plot(dat,pch=19,col=col2alpha(rep("red",4000),seq(0,1,len=4000)))

# Two colors, same alpha
plot(dat,pch=19,col=col2alpha(rep(c("red","purple"),each=2000),.2))

# Four colors, gradient of transparency for each color
plot(dat,pch=19,col=col2alpha(rep(c("blue","purple","red","orange"),each=1000),seq(.1,.6,len=1000)))

# Alpha transparency applied to a gradient of colors
plot(dat,pch=19,col=col2alpha(rainbow(4000),.5))

Run the code above in your browser using DataLab