A colour aesthetic for annotation that automatically contrasts with fill. Can be spliced into ggplot2::aes with rlang::!!!.
Arguments
- mode_family
The mode family to optimise light and dark colours for. Options are "light", "grey" or "dark".
- dark
A dark colour. If NULL, uses
mode_family
optimised colour.- light
A light colour. If NULL, uses
mode_family
optimised colour.
Examples
library(ggplot2)
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
library(stringr)
library(palmerpenguins)
set_blanket()
penguins |>
count(species, sex) |>
gg_col(
x = sex,
y = n,
col = species,
label = n,
position = position_dodge2(preserve = "single"),
width = 0.75,
x_labels = \(x) str_to_sentence(x),
) +
geom_text(
mapping = aes_contrast(),
# mapping = aes(!!!aes_contrast()),
position = position_dodge2(width = 0.75, preserve = "single"),
vjust = 1.33,
show.legend = FALSE,
)
penguins |>
count(species, sex) |>
gg_col(
x = sex,
y = n,
col = species,
label = n,
position = position_dodge2(preserve = "single"),
width = 0.75,
x_labels = \(x) str_to_sentence(x),
mode = dark_mode_r(),
) +
geom_text(
mapping = aes_contrast("dark"),
#' mapping = aes(!!!aes_contrast("dark")),
position = position_dodge2(width = 0.75, preserve = "single"),
vjust = 1.33,
show.legend = FALSE,
)