| hex_bw | R Documentation | 
You could use auto_contrast as a shortcut of
aes(colour = after_scale(hex_bw(.data$fill))). You should use !!! to
inject it within ggplot2::aes() (see examples).
hex_bw_threshold() is a variation of hex_bw(). For values below
threshold, black ("#000000") will always be returned, regardless of
hex_code.
hex_bw(hex_code)
hex_bw_threshold(hex_code, values, threshold)
auto_contrast
hex_code | 
 Background color in hex-format.  | 
values | 
 Values to be compared.  | 
threshold | 
 Threshold.  | 
An object of class uneval of length 1.
Either black or white, in hex-format
Adapted from saros for hex_code() and from
https://github.com/teunbrand/ggplot_tricks?tab=readme-ov-file#text-contrast
for auto_contrast.
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
  )
ggplot(diamonds) +
  aes(x = cut, fill = color, label = after_stat(count)) +
  geom_bar() +
  geom_text(
    mapping = auto_contrast,
    position = position_stack(.5),
    stat = "count",
    size = 2
  )
ggplot(diamonds) +
  aes(x = cut, fill = color, label = after_stat(count), !!!auto_contrast) +
  geom_bar() +
  geom_text(
    mapping = auto_contrast,
    position = position_stack(.5),
    stat = "count",
    size = 2
  )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.