color.theme {midr} | R Documentation |
Color Themes for Graphics
Description
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 |
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
.
Value
color.theme()
returns a "color.theme" object containing following components:
ramp |
the function that takes a numeric vector |
palette |
the function that takes an integer |
type |
the type of the color theme; "sequential", "diverging" or "qualitative". |
name |
the name of the color theme. |
Examples
ct <- color.theme("Mako")
ct$palette(5L)
ct$ramp(seq.int(0, 1, 1/4))
ct <- color.theme("RdBu")
ct$palette(5L)
ct$ramp(seq.int(0, 1, 1/4))
ct <- color.theme("Tableau 10")
ct$palette(10L)
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)