Skip to contents

Choose black or white text using the larger relative-luminance contrast ratio. Transparent fills are composited over an opaque background first.

Usage

contrast_text(colors, alpha = NULL, background = "white")

Arguments

colors

A vector of R colors. Missing colors are transparent.

alpha

NULL to use each color's alpha channel, or a finite numeric opacity in [0, 1], either one value or one per color.

background

One opaque R background color. Default is white.

Value

A character vector of black or white, with the names of colors.

Examples

contrast_text(c("navy", "ivory"))
#> [1] "white" "black"
contrast_text(c("black", "black"), alpha = c(1, 0.2))
#> [1] "white" "black"