Selects whether black or white has the greater contrast with a user- supplied color. Useful for choosing a text color to overlay on a block-color background, like value labels over the bars of a bar chart. Calculated as per cr_get_ratio. Defaults to black in the case of a tie.

cr_choose_bw(col_bg)

Arguments

col_bg

A character vector of colors against which to select either black or white, whichever has maximum contrast. Supply colors as six-digit hex values preceded by '#', or named colors from colors.

Value

A character vector of values "black" or "white". The length matches the input.

Examples

cr_choose_bw(c("white", "gray90", "gray50", "gray10", "black"))
#> [1] "black" "black" "black" "white" "white"