alpha | R Documentation |
Modify color transparency, vectorized in both x
and alpha
(when both are vectors, they must be the same length).
alpha(x, alpha = 0.5)
x |
vector of colors specified as hex strings or named R colors. |
alpha |
transparency, number in |
Most other operations in chroma do not support alpha channels (because the underlying library, chroma.js, does not output 8 digits hex color specifications, which describe r, g, b, and a channels). Therefore, any manipulation of transparency must be done last.
as.hex("red") alpha("red") show_col(c("red", alpha("red"))) # Vectorised in both x and alpha, as long as the lengths are compatible alpha(c("red", "green", "blue"), 0.5) alpha("red", c(0.2, 0.5, 0.7)) alpha(c("red", "green", "blue"), c(0.2, 0.5, 0.7)) alpha(c("red", "green", "blue", "purple"), c(0.2, 0.5)) ## Not run: alpha(c("red", "green", "blue", "purple"), c(0.2, 0.5, 0.7)) # = fails because arguments have incompatible lengths (x = 4, alpha = 3) ## End(Not run) # Beware, other functions do not support alpha channels mix(alpha("red"), alpha("blue")) mix("red", "blue") # = both are the same, and fully opaque. Use alpha last alpha(mix("red", "blue"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.