aes_colour_contrast: A colour aesthetic for contrast

View source: R/aes.R

aes_colour_contrastR Documentation

A colour aesthetic for contrast

Description

A colour aesthetic to contrast with a fill aesthetic. Can be spliced into ggplot2::aes with rlang::!!!.

Usage

aes_colour_contrast(..., dark = "#121B24FF", light = "#FFFFFFFF")

Arguments

...

Provided to force user argument naming etc.

dark

A dark colour.

light

A light colour.

Value

A ggplot2 aesthetic

Examples

library(ggplot2)
library(dplyr)
library(stringr)
library(palmerpenguins)

set_blanket()

penguins |>
  count(species, sex) |>
  gg_col(
    x = sex,
    y = n,
    col = species,
    label = n,
    position = position_dodge(preserve = "single"),
    width = 0.75,
    x_labels = \(x) str_to_sentence(x),
  ) +
  geom_text(
    mapping = aes_colour_contrast(),
    position = position_dodge(width = 0.75, preserve = "single"),
    vjust = 1.33,
    show.legend = FALSE,
  )

penguins |>
  count(species, sex) |>
  gg_col(
    x = sex,
    y = n,
    col = species,
    position = position_dodge(preserve = "single"),
    width = 0.75,
    x_labels = \(x) str_to_sentence(x),
    mode = dark_mode_r(),
  ) +
  geom_text(
    mapping = aes(label = n, !!!aes_colour_contrast(dark = darkness[3], light = darkness[1])),
    position = position_dodge(width = 0.75, preserve = "single"),
    vjust = 1.33,
    show.legend = FALSE,
  )

davidhodge931/ggblanket documentation built on Dec. 22, 2024, 9:10 p.m.