specplot: Color Spectrum Plot

View source: R/specplot.R

specplotR Documentation

Color Spectrum Plot

Description

Visualization of color palettes (given as hex codes) in HCL and/or RGB coordinates.

Usage

specplot(
  x,
  y = NULL,
  rgb = FALSE,
  hcl = TRUE,
  fix = TRUE,
  cex = 1,
  type = "l",
  lwd = 2 * cex,
  lty = 1,
  pch = NULL,
  mar = NULL,
  oma = NULL,
  main = NULL,
  legend = TRUE,
  palette = TRUE,
  plot = TRUE,
  ...
)

Arguments

x

character vector containing color hex codes.

y

optional second character vector containing further color hex codes, to be used for comparing two palettes (x vs. y).

rgb

logical or color specification. Should the RGB spectrum be visualized? Can also be a vector of three colors for the legend of R/G/B coordinates.

hcl

logical or color specification. Should the HCL spectrum be visualized? Can also be a vector of three colors for the legend of H/C/L coordinates.

fix

logical. Should the hues be fixed to be on a smooth(er) curve? For details see below.

cex

numeric. Character extension for figure axes and labels.

type, lwd, lty, pch

plotting parameters passed to lines for drawing the RGB and HCL coordinates, respectively. Can be vectors of length 3.

mar, oma

numeric or logical. Either numeric vectors of length 4 giving the (outer) margins or a logical indicating whether mar/oma should be set.

main

character. Main title of the plot.

legend

logical. Should legends for the coordinates be plotted?

palette

logical. Should the given palette x be plotted?

plot

logical. Should the RGB and/or HCL coordinates be plotted?

...

currently not used.

Details

The function specplot transforms a given color palette in hex codes into their HCL (polarLUV) and/or RGB (sRGB) coordinates. As the hues for low-chroma colors are not (or poorly) identified, by default a smoothing is applied to the hues (fix = TRUE). Also, to avoid jumps from 0 to 360 or vice versa, the hue coordinates are shifted suitably.

By default (plot = TRUE), the resulting HCL and optionally RGB coordinates are visualized by simple line plots along with the color palette x itself. The x-axis simply gives the ordering of the colors in the palette The y-axis depicts the following information: (1) Hue is drawn in red and coordinates are indicated on the axis on the right with range [0, 360] or (if necessary) [-360, 360]. (2) Chroma is drawn in green with coordinates on the left axis. The range [0, 100] is used unless the palette necessitates higher chroma values. (3) Luminance is drawn in blue with coordinates on the left axis in the range [0, 100]. Luminance (and hence also chroma) is on the left axis because it is arguably most important for understanding the type of palette (qualitative vs. sequential vs. diverging). To facilitate reading the legend the reversed order Luminance / Chroma / Hue is used so that the legend labels are closer to the axis they pertain to.

For comparing two palettes, specplot(x, y) can be used which adds lines (dashed, by default) corresponding to the y palette HCL/RGB coordinates in the display.

Value

specplot invisibly returns a list with components

HCL

a matrix of HCL coordinates,

RGB

a matrix of sRGB coordinates,

hex

original color palette x.

Author(s)

Reto Stauffer, Achim Zeileis

References

Zeileis A, Hornik K, Murrell P (2009). Escaping RGBland: Selecting Colors for Statistical Graphics. Computational Statistics & Data Analysis, 53, 3259–3270. doi: 10.1016/j.csda.2008.11.033 Preprint available from https://www.zeileis.org/papers/Zeileis+Hornik+Murrell-2009.pdf.

Stauffer R, Mayr GJ, Dabernig M, Zeileis A (2015). Somewhere over the Rainbow: How to Make Effective Use of Colors in Meteorological Visualizations. Bulletin of the American Meteorological Society, 96(2), 203–216. doi: 10.1175/BAMS-D-13-00155.1

Zeileis A, Fisher JC, Hornik K, Ihaka R, McWhite CD, Murrell P, Stauffer R, Wilke CO (2020). “colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.” Journal of Statistical Software, 96(1), 1–49. doi: 10.18637/jss.v096.i01

See Also

hcl_palettes, hclplot

Examples

## spectrum of the (in)famous RGB rainbow palette (in both RGB and HCL)
specplot(rainbow(100), rgb = TRUE)

## spectrum of HCL-based palettes: qualitative/sequential/diverging
specplot(qualitative_hcl(100, "Set 2"))
specplot(sequential_hcl(100, "Blues 2"))
specplot(diverging_hcl(100, "Blue-Red"))

## return computed RGB and HCL coordinates
res <- specplot(rainbow(10), plot = FALSE)
print(res)

colorspace documentation built on Jan. 25, 2023, 3:12 p.m.