View source: R/compute_average.R
average | R Documentation |
Average several colors
average(x, model = "lrgb", na.rm = FALSE)
x |
vector of colors specified as hex strings or named R colors. |
model |
string defining the color model to compute the mix in; valid models are |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds. |
A vector of colors specified as hex codes
Other color manipulation functions:
blend()
,
channel()
,
darken()
,
luminance()
,
mix()
,
saturate()
average(c("red", "blue"))
average(c("red", "blue", "green"))
# show the input colors, then white, then the average
show_ave <- function(x, ...) {show_col(c(x, "white", average(x, ...)))}
show_ave(c("#FEF213", "#146EFD"))
show_ave(hue_colors(5))
show_ave(brewer_colors(5, name="Set3"))
show_ave(cubehelix_colors(5))
# so averaging produces brown, most of the time, but not always:
show_ave(brewer_colors(5, name="Greens"))
# beware that numerical color averaging is not the same as blending
# pigments, in particular in non-rgb spaces
show_ave(c("#FEF213", "#A0BD71", "#146EFD"))
show_ave(c("#FEF213", "#A0BD71", "#146EFD"), model="hcl")
show_ave(c("#FEF213", "#A0BD71", "#146EFD"), model="hsv")
show_ave(c("#FEF213", "#A0BD71", "#146EFD"), model="lab")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.