Skip to contents

best_contrast() finds the color in y with the highest contrast to the color x.

Usage

best_contrast(x, y = c("#010101", "#FFFFFF"))

Arguments

x

A vector of colors as described in col of color(). Must not contain any NA.

y

A vector of colors as described in col of color(). Must not contain any NA.

Value

A vector of the same length as x with, for each element of x, the element of y that has the highest contrast to x.

Examples

best_contrast("red")
#> [1] "#010101"
best_contrast("grey20")
#> [1] "#FFFFFF"
best_contrast("white")
#> [1] "#010101"

best_contrast(rainbow(10), rainbow(3))
#>  [1] "#00FF00" "#0000FF" "#0000FF" "#0000FF" "#0000FF" "#0000FF" "#00FF00"
#>  [8] "#00FF00" "#00FF00" "#00FF00"