Automatic Generation of Qualitative Color Palettes

Automatic generation of distinct qualitative color palettes, optionally adapted to color blindness. It takes a subspace of the HSL color space as input and projects it to the DIN99d color space where it selects and return colors that are maximally distinct.


qualpalr

qualpalr generates distinct qualitative color palettes, primarily for use in R graphics. Given n (the number of colors to generate), along with a subset in the hsl color space (a cylindrical representation of the RGB color space) qualpalr attempts to find the n colors in the provided color subspace that maximize the smallest pairwise color difference. This is done by projecting the color subset from the HSL color space to the DIN99d space. DIN99d is (approximately) perceptually uniform, that is, the euclidean distance between two colors in the space is proportional to their perceived difference.

qualpalr was inspired by i want hue.

library(qualpalr) # 0.1 and 0.5, and lightness from 0.6 to 0.85
pal <- qualpal(n = 4, list(h = c(0, 360), s = c(0.1, 0.5), l = c(0.6, 0.85)))
 
# Look at the colors in hex format
pal$hex
#> [1] "#C072C9" "#6FCB6F" "#78A7CA" "#D1AC97"
 
# Create a palette using one of the predefined color subspaces, adapted to color
# vision deficiency
pal2 <- qualpal(n = 4, colorspace = "pretty", cvd = "deutan", cvd_severity = 0.5)
 
# Distance matrix of the DIN99d color differences
pal2$de_DIN99d
#>    1  2  3
#> 2 19      
#> 3 20 20   
#> 4 28 19 18

pairs() and plot() methods have been prepared for objects created with qualpal.

plot(pal)
pairs(pal, colorspace = "hsl")

The current CRAN release can be installed by running

install.packages("qualpalr")

The development version can be installed by running

devtools::install_github("jolars/qualpalr")

Versioning is based on semantic versioning.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

qualpalr is open source software, licensed under GPL-3.

News

qualpalr 0.3.1

  • Dropped a C++ header that caused the package build to fail on some platforms.
  • Fixed issues with unitialized variables in the internal farthest points optimizer.

qualpalr 0.3.0

  • Improved algorithm for finding distinct colors. (For details see this.)
  • Revamped the color deficiency handling to include almost all cases of color deficiency using the methods described in Machado 2010, now including tritanopia as well as anomalous trichromacies (deuteranomaly, tritanomaly, and protanomaly). This is controlled via the cvd_severity argument to qualpal() that allows the user to set the severity of color deficiency to adapt to -- 0 for normal vision and 1 for dichromatic vision (protanopia, deuteranopia, or tritanopia).
  • Distance and color picking algorithms have been rewritten in C++ using Rcpp, RcppParallel, and RcppArmadillo.
  • Phased out the ... argument to qualpal.
  • Lightness range of the predefined rainbow palette increased to [0, 1].
  • Changed argument name of colorblind to cvd (for color vision deficiency) since the function now adapts to less severe versions of color deficiency. Using colorblind is deprecated and will throw a warning.
  • Fixed typos and invalid links in the Introduction to qualpalr vignette.

qualpalr 0.2.1

  • Dropped daltonization since it effectively transposed the color subspace given by the user. qualpalr now instead only transforms the given color subspace to simulate protanopia or deuteranopia and then picks colors. This has the side-effect of decreasing the distinctness of color palettes when colorblind is used, but is more consistent with user input.
  • Simulations for tritanopia were dropped since there is no reliable source to explain how sRGB ranges should be converted (as there is for deuteranopia and protanopia in Vienot et al 1999).
  • Added tests using data from Vienot et al 1999 to check that color blind simulations work properly.
  • Fixed a sampling bug wherein the square root of saturation was taken after scaling to the provided range, which generated different ranges than intended.
  • Switched to the sobol quasi-random sequence instead of torus.

qualpalr 0.2.0

  • Redesigned the method by which qualpal picks colors. Now initializes a point cloud of colors, projects it to DIN99d space, and picks points greedily.
  • Introduced real methods of adapting colors to color blindness by daltonizing color subspaces before picking colors from them.
  • The introduction to qualpalr vignette has been expanded with a thorough description of how qualpalr picks colors.
  • Moved from using grDevices::convertColor to formulas from Bruce Lindbloom for color conversions, since the former function inaccurately converts colors.
  • Deprecated ... in qualpal since the function no longer uses an optimizer.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("qualpalr")

0.3.1 by Johan Larsson, 2 months ago


https://github.com/jolars/qualpalr


Report a bug at https://github.com/jolars/qualpalr/issues


Browse source code at https://github.com/cran/qualpalr


Authors: Johan Larsson [aut, cre]


Documentation:   PDF Manual  


GPL-3 license


Imports randtoolbox, graphics, stats, grDevices, assertthat, Rcpp, RcppParallel

Suggests testthat, knitr, maps, rmarkdown, rgl

Linking to Rcpp, RcppParallel, RcppArmadillo

System requirements: GNU make


See at CRAN