combine_alphas | R Documentation |
Combine alpha transparency values with additive logic
combine_alphas(x, max_alpha = 1, ...)
x |
|
max_alpha |
|
... |
additional arguments are ignored. |
Alpha transparency is defined as 0 for fully transparent, and 1
(or max_alpha
) for fully opaque (not transparent).
The purpose is to permit combining multiple colors, where the
alpha transparency builds over time. Each color should contribute
some proportional fraction to the overall opacity of the final
color.
The basic formula:
new_alpha <- alpha1 + (1 - alpha1) * alpha2
Or when max_alpha
is defined:
new_alpha <- alpha1 + (max_alpha - alpha1) * alpha2
Any NA
values are considered equivalent to 0
and are
therefore not applied.
All input alpha values are restricted to values between
0
and max_alpha
.
For more than two values, each value is applied in series, which works out to the same result if applied in any order.
numeric
value after combining alpha values.
Other colorjam display:
color_pie()
,
showDichromat()
# it progressively fills 50% of remaining transparency
combine_alphas(c(0.5, 0.5))
combine_alphas(c(0.5, 0.5, 0.5))
combine_alphas(c(0.5, 0.5, 0.5, 0.5))
base_alpha <- 0.5;
new_alphas <- sapply(1:5, function(i){
combine_alphas(rep(base_alpha, i))
})
names(new_alphas) <- seq_along(new_alphas);
bp <- barplot(new_alphas, ylim=c(0, 1.1), col="navy",
xlab=paste0("Number of ",
base_alpha,
" alpha values combined"))
abline(h=1, lty=2);
jamba::shadowText(x=bp[, 1], y=new_alphas,
col="white", cex=1.5,
pos=1,
xpd=TRUE,
label=round(new_alphas, digits=3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.