Learn R Programming

ggpp (version 0.5.1)

dark_or_light: Chose between dark and light color

Description

Chose between a pair of contrasting dark and light colors based on a weighted mean of RGB channels of a color. This function implements a simple approach to the choice for a color of a plot element to ensure it is visible against a background color.

Usage

dark_or_light(
  colors,
  threshold = 0.45,
  dark.color = "black",
  light.color = "white"
)

Arguments

colors

A vector of color definitions or color names in the background.

threshold

numeric A value in [0..1] indicating the switch point between dark and light background.

dark.color, light.color

A color definition or color name to return for dark and light objects (orveplotted on light and dark backgrounds, respectively).

Examples

Run this code

dark_or_light("yellow")
dark_or_light("darkblue")
dark_or_light("#FFFFFF")
dark_or_light("#FFFFFF", dark.color = "darkblue", light.color = "lightgrey")
dark_or_light("#000000", dark.color = "darkblue", light.color = "lightgrey")

Run the code above in your browser using DataLab