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 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.
Let's create a palette of 4 colors of hues from 0 to 360, saturation between 0.1 and 0.5, and lightness from 0.6 to 0.85.
library(qualpalr)pal <- qualpal(n = 4, list(h = c(0, 360), s = c(0.1, 0.5), l = c(0.6, 0.85)))
We can retrieve the generated colors in hex format
Altneratively, we can create a palette using one of the predefined color subspaces and, optionally, adapt it to color deficiency (here deuteranomaly).
pal2 <- qualpal(n = 4, colorspace = "pretty", cvd = "deutan",cvd_severity = 0.5)
We can look at a distance matrix of the pairwise color differences from the palette we have generated.
pal2$de_DIN99d#> #D4C76F #616FC8 #D0E0E8#> #616FC8 29.14409#> #D0E0E8 18.78602 21.76547#> #A08587 18.59491 18.38472 18.34490
The palette may also be plotted with in a multidimensional scaling plot generated from the distance matrix of the colors in the palette.
Or it might be plotted in one of the provided color spaces as a scatterplot matrix.
pairs(pal2, colorspace = "HSL")
The current CRAN release can be installed by running
The development version can be installed by running
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.
colorspaceto be a string.
autopal()which was broken since the minimum color difference returned was always 0 due to a bug in
autopal()is a new function that tweaks the amount of color vision deficiency adapation to match a target color difference.
colorspacenow also accepts a
data.frameof RGB colors.
qualpal()sorts palettes in order of increasing color distinctness.
colorblindhas been made defunct.
qualpal()has been improved.
qualpal()that allows the user to set the severity of color deficiency to adapt to --
0for normal vision and
1for dichromatic vision (protanopia, deuteranopia, or tritanopia).
cvd(for color vision deficiency) since the function now adapts to less severe versions of color deficiency. Using
colorblindis deprecated and will throw a warning.
colorblindis used, but is more consistent with user input.
grDevices::convertColorto formulas from Bruce Lindbloom for color conversions, since the former function inaccurately converts colors.
qualpalsince the function no longer uses an optimizer.