Skip to contents

color.theme() returns an object of class "color.theme" that provides two types of color functions.

Usage

color.theme(
  colors,
  type = c("sequential", "qualitative", "diverging"),
  name = NULL,
  pkg = NULL,
  ...
)

# S3 method for class 'color.theme'
plot(x, n = NULL, text = x$name, ...)

# S3 method for class 'color.theme'
print(x, display = TRUE, ...)

Arguments

colors

one of the following: a color theme name such as "Viridis" with the optional suffix "_r" for color themes in reverse order ("Viridis_r"), a character vector of color names, a palette function, or a ramp function to be used to create a color theme.

type

a character string specifying the type of the color theme: One of "sequential", "qualitative" or "diverging".

name

an optional character string, specifying the name of the color theme.

pkg

an optional character string, specifying the package in which the palette is to be searched for. Available options include "viridisLite", "RColorBrewer", "khroma", "grDevices" and "midr".

...

optional arguments to be passed to palette or ramp functions.

x

a "color.theme" object to be displayed.

n

integer. the number of colors.

text

a character string to be displayed.

display

logical. If TRUE, colors are displayed in the plot area.

Value

color.theme() returns a "color.theme" object containing following components:

ramp

the function that takes a numeric vector x of the values within [0, 1] and returns a color name vector.

palette

the function that takes an integer n and returns a color name vector of length n.

type

the type of the color theme; "sequential", "diverging" or "qualitative".

name

the name of the color theme.

Details

"color.theme" objects is a container of the two types of color functions: palette(n) returns a color name vector of length n, and ramp(x) returns color names for each values of x within [0, 1]. Some color themes are "qualitative" and do not contain ramp() function. The color palettes implemented in the following packages are available: grDevices, viridisLite, RColorBrewer and khroma.

Examples

ct <- color.theme("Mako")
ct$palette(5L)
#> [1] "#070707" "#423460" "#007FA8" "#48C2B4" "#E0F7E1"
ct$ramp(seq.int(0, 1, 1/4))
#> [1] "#060606" "#3E365E" "#007FA7" "#5BC1B7" "#DFF7E0"
ct <- color.theme("RdBu")
ct$palette(5L)
#> [1] "#66001F" "#E58366" "#F7F7F7" "#6DABD0" "#053060"
ct$ramp(seq.int(0, 1, 1/4))
#> [1] "#66001F" "#E58366" "#F7F7F7" "#6DABD0" "#053060"
ct <- color.theme("Tableau 10")
ct$palette(10L)
#>  [1] "#4E79A7" "#F28E2B" "#E15759" "#76B7B2" "#59A14F" "#EDC948" "#B07AA1"
#>  [8] "#FF9DA7" "#9C755F" "#BAB0AC"
pals <- c("midr", "grayscale", "bluescale", "shap", "DALEX")
pals <- unique(c(pals, hcl.pals(), palette.pals()))
pals <- lapply(pals, color.theme)
old.par <- par(no.readonly = TRUE)
par(mfrow = c(5L, 2L))
for (pal in pals) plot(pal, text = paste(pal$name, "-", pal$type))













par(old.par)