c4a: Get a cols4all color palette

View source: R/c4a.R

c4aR Documentation

Get a cols4all color palette

Description

Get a cols4all color palette: c4a returns the colors of the specified palette, c4a_na returns the color for missing value that is associated with the specified palette, and c4a_ramp returns a color ramp function. Run c4a_gui to see all available palettes, which are also listed with c4a_palettes.

Usage

c4a(
  palette = NULL,
  n = NA,
  m = NA,
  type = c("cat", "seq", "div", "cyc", "bivs", "bivc", "bivd", "bivg"),
  reverse = FALSE,
  order = NULL,
  range = NA,
  colorsort = "orig",
  format = c("hex", "rgb", "hcl", "RGB", "XYZ", "HSV", "HLS", "LAB", "polarLAB", "LUV",
    "polarLUV"),
  nm_invalid = c("error", "repeat", "interpolate"),
  verbose = TRUE
)

c4a_ramp(..., space = c("rgb", "Lab"), interpolate = c("linear", "spline"))

c4a_na(
  palette = NULL,
  type = c("cat", "seq", "div", "cyc", "bivs", "bivc", "bivd", "bivg"),
  verbose = TRUE
)

Arguments

palette

name of the palette. See c4a_palettes for available palettes. If omitted, the default palette is provided by c4a_default_palette. The palette name can be prefixed with a "-" symbol, which will reverse the palette (this can also be done with the reverse argument).

n

number of colors. If omitted then: for type "cat" the maximum number of colors is returned, for types "seq", "div", and "cyc", 7 , 9, and 9 colors respectively.

m

number of rows in case type is bivariate, so one of "bivs", "bivc", "bivd" or "bivg" (see c4a_types for descriptions)

type

type of color palette, in case palette is not specified: one of "cat", "seq", "div", "cyc", "bivs", "bivc", "bivd", "bivg". Run c4a_types for descriptions.

reverse

should the palette be reversed?

order

order of colors. Only applicable for "cat" palettes

range

a vector of two numbers between 0 and 1 that determine the range that is used for sequential and diverging palettes. The first number determines where the palette begins, and the second number where it ends. For sequential "seq" palettes, 0 means the leftmost (normally lightest) color, and 1 the rightmost (often darkest) color. For diverging "seq" palettes, 0 means the middle color, and 1 both extremes. If only one number is provided, this number is interpreted as the endpoint (with 0 taken as the start).

colorsort

Sort the colors. Options: "orig" (original order), "Hx" (hue, where x is a starting number from 0 to 360), "C" (chroma), "L" (luminance). All these options are available for "cat" palettes, only the last one for "seq", and none for the other palette types.

format

format of the colors. One of: "hex" character vector of hex color values, "rgb" 3 column matrix of RGB values, "hcl" 3-column matrix of HCL values, or one of the color classes from colorspace

nm_invalid

what should be done in case n or m is larger than the maximum number of colors or smaller than the minimum number? Options are "error" (an error is returned), "repeat", the palette is repeated, "interpolate" colors are interpolated. For categorical "cat" palettes only.

verbose

should messages be printed?

...

passed on to c4a.

space

a character string; interpolation in RGB or CIE Lab color spaces

interpolate

use spline or linear interpolation

Value

A vector of colors (c4a) and a color (c4a_na)

Examples

# get the colors from brewer.set3 and plot them
set3 <- c4a("brewer.set3")
c4a_plot_hex(set3, nrows = 1)

c4a("hcl.set2", n = 36) |> c4a_plot_hex()
c4a("-hcl.set2", n = 12) |> c4a_plot_hex()

# how to know which palettes are avaiable?
# 1) Via the interactive tool:
## Not run: 
	c4a_gui()

## End(Not run)

# 2) Via the overview function:
c4a_palettes(type = "cat")
c4a_palettes(series = "brewer")
c4a_palettes(type = "cat", series = "brewer")
# Run c4a_overview() to see which are available

# 3) Via .P
.P$brewer$cat$set3

# each palette contains a color for missing values

c4a("carto.safe", 7)
c4a_na("carto.safe")

c4a_plot_hex("carto.safe", n = 7, include.na = TRUE)


c4a_plot_hex("carto.safe", n = 7, include.na = TRUE)
# same (but shorter) as
# c4a_plot_hex(c(c4a("carto.safe", 7), c4a_na("carto.safe")), include.na = TRUE)


# color ramp
c4a("viridis", 100) |> c4a_plot()
c4a_ramp("viridis")(100) |> c4a_plot()

cols4all documentation built on Oct. 17, 2024, 1:07 a.m.