Learn R Programming

ggstats (version 0.7.0)

hex_bw: Identify a suitable font color (black or white) given a background HEX color

Description

hex_bw_threshold() is a variation of hex_bw(). For values below threshold, black ("#000000") will always be returned, regardless of hex_code.

Usage

hex_bw(hex_code)

hex_bw_threshold(hex_code, values, threshold)

Value

Either black or white, in hex-format

Arguments

hex_code

Background color in hex-format.

values

Values to be compared.

threshold

Threshold.

Examples

Run this code
hex_bw("#0dadfd")

library(ggplot2)
ggplot(diamonds) +
  aes(x = cut, fill = color, label = after_stat(count)) +
  geom_bar() +
  geom_text(
    mapping = aes(color = after_scale(hex_bw(.data$fill))),
    position = position_stack(.5),
    stat = "count",
    size = 2
  )

Run the code above in your browser using DataLab