col2alpha | R Documentation |
Adds transparency to a color or a vector of colors by specifying one or several alpha values.
col2alpha(color,alpha = 0.5)
color |
a (vector of) color codes or names |
alpha |
a value (or vector of values) between 0 (full transparency) and 1 (no transparency). |
When the size of color
and alpha
vectors are different, alpha
values are recycled.
A (vector) of color code(s).
Benoit Simon-Bouhet
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.