choose_dark_or_light {xaringanthemer} | R Documentation |
Choose dark or light color
Description
Takes a color input as x
and returns either the black or white color (or
expression) if dark or light text should be used over the input color for
best contrast. Follows W3C Recommendations.
Usage
choose_dark_or_light(x, black = "#000000", white = "#FFFFFF")
Arguments
x |
The background color (hex) |
black |
Text or foreground color, e.g. "#222" or
|
white |
Text or foreground color or expression, e.g. "#EEE" or
|
Value
The black
color or white
color according to which color provides
the greates contrast with the input color.
References
https://stackoverflow.com/a/3943023/2022615
Examples
light_green <- "#c4d6b0"
contrast_green <- choose_dark_or_light(light_green)
dark_purple <- "#381d2a"
contrast_purple <- choose_dark_or_light(dark_purple)
if (requireNamespace("scales", quietly = TRUE)) {
scales::show_col(c(light_green, contrast_green, dark_purple, contrast_purple))
}
[Package xaringanthemer version 0.4.2 Index]