A wrapper around a variety of scale_color_-() / scale_fill_-() functions.

scale_color_add_on(
  aes = "color",
  variable = "numeric",
  clrsp = NULL,
  clrp = NULL,
  ...
)

Arguments

aes

Character value. Either 'color' or 'fill'. Denotes the used aesthetic.

variable

The variable that is mapped onto the denoted aesthetic or a character value - one of 'numeric', 'discrete'.

clrsp

Character value. The color spectrum of choice if variable is numeric. Run confuns::all_colorspectra() to see all valid input choices.

(Ignored if variable is discrete)

clrp

Character value. The color panel of choice if variable is discrete Run confuns::all_colorpanels() to see all valid input choices.

(Ignored if variable is numeric)

...

Additional arguments given to the respective function.

  • ggplot2::scale_color_viridis_c(...): If variable is numeric and clrsp is one of 'cividis', 'viridis', 'inferno', 'magma', 'plasma'

  • colorspace::scale_<aes>_continuous_sequential(...): If variable is numeric and clrsp is sequential

  • colorspace::scale_<aes>_continuous_diverging(...): If variable is numeric and clrsp is diverging

  • ggplot2::scale_<aes>_manual(...): If variable is categorical.

Value

An unnamed list containing the ggproto object.

Details

If the specified clrp does not contain enough colors to cover the specified variable NULL is returned - which makes the call to ggplot2::ggplot() use the default ggplot2 color panel.

Make sure to use correct capitalization and white spaces denoting the color panel or -spectrum of choice.

Examples

library(ggplot2)
#> Want to understand how all the pieces fit together? Read R for Data #> Science: https://r4ds.had.co.nz/
ggplot(mtcars, aes(x = qsec, y = wt)) + geom_point(aes(color = mpg)) + scale_color_add_on(aes = "color", variable = mtcars$mpg, clrsp = "Reds 3")