Color is essential in many charts and maps. There are a lot of color
palettes to choose from: most visualization software tools have their
own palettes and there are many other series of color palettes, such as
ColorBrewer (Harrower and Brewer, 2003). To make life easier for R
users, there are a couple of packages that contain a large collection of
palettes, most notably
pals (Wright, 2021) with 139 and
paletteer (Hvitfeldt, 2021) with 2569 (!) palettes.
However, people often cannot see the trees through the forest, so
therefore they tend to stick with the color palettes they know, or with
the most popular ones.
cols4all package also contains a large collection of
palettes (to be precise 436 at the time of writing), but with the
central question: which palettes are good and why? There is no simple
answer, since there are many aspects to take into account, which may
have opposite effects. In
cols4all we examine the following
Color Blind Friendliness First and most importantly, is a palette suitable for colorblind people? About 5% of all humans have a color vision deficiency, and we want to include them; hence the package name “colors for all”.
HCL Analysis Does a palette work well for statistical purposes? We analyse this with the HCL (hue-chroma-luminance) color space. Concrete questions for these analysis are the following. How vivid are colors? Do the colors stand out about equally (which we call “fairness”)? What hue ranges are used for quantitative color palettes?
Contrast What is the contrast between the colors in the palette? We focus on two specific questions: 1) How well is text readable (also for people with a visual impairment)? 2) Are border lines needed to separate colors?
3D Blues Does the palette contain blue colors that could result in a floating effect?
Currently, cols4all contains palettes from several popular and lesser known color palette series: “brewer”, “c4a”, “carto”, “hcl”, “kovesi”, “met”, “parks”, “poly”, “scico”, “seaborn”, “stevens”, “tableau”, “tol”, “viridis” , and “wes”. Stand-alone palettes that are included have been put in the series “misc” (miscellaneous). Own palettes series can be added as well.
Color palettes are organized and made consistent with each other. For instance, all sequential palettes go from light to dark. Furthermore, for each color palette a color for missing values is assigned, which is especially important for spatial data visualization. Currently we support several types: categorical (qualitative) palettes, sequential palettes, diverging palettes, and bivariate palettes (divided into four subtypes).
The figure above shows the main tool of this package, a dashboard. The first tab page contains an overview table of all palettes (given the input selection criteria). The other tab pages are for further palette-wise analyses.
Color palettes also are important in areas other than data visualization, such as arts, web design, and fashion. The same aspects apply as well here, but obviously different criteria apply: the colors of a dress don’t have to be distinguished by colorblind people, websites often contain colors that purposely stand out more than others, and there are paintings that purposely use visual illusions.
cols4all is available on CRAN and can be installed
install.packages("cols4all", dependencies = TRUE)
The latest development version can be installed as follows:
::install_github("mtennekes/cols4all", dependencies = TRUE)remotes
Load the package:
The main tool is a dashboard (shown above), which is started with:
What types and series are available?
c4a_types() #> type description #> 1 cat categorical #> 2 seq sequential #> 3 div diverging #> 4 bivs bivariate (sequential x sequential) #> 5 bivc bivariate (sequential x categorical) #> 6 bivd bivariate (sequential x diverging) #> 7 bivg bivariate (sequential x desaturated) c4a_series() #> series description #> 1 brewer ColorBrewer palettes #> 2 c4a cols4all palettes (in development) #> 3 carto Palettes designed by CARTO #> 4 hcl Palettes from the Hue Chroma Luminance color space #> 5 kovesi Palettes designed by Peter Kovesi #> 6 met Palettes inspired by The Metropolitan Museum of Art #> 7 misc Miscellaneous palettes #> 8 parks Palettes inspired by National Parks #> 9 poly Qualitative palettes with many colors #> 10 scico Scientific colour map palettes by Fabio Crameri #> 11 seaborn Palettes from the Python library Seaborn #> 12 stevens Bivariate palettes by Joshua Stevens #> 13 tableau Palettes designed by Tableau #> 14 tol Palettes designed by Paul Tol #> 15 viridis Palettes fom the Python library matplotlib #> 16 wes Palettes from Wes Anderson movies
How many palettes per type x series?
c4a_overview() #> cat seq div bivs bivc bivd bivg #> brewer 8 18 9 2 1 1 NA #> c4a NA NA 2 2 NA 2 5 #> carto 6 21 7 NA NA NA NA #> hcl 9 23 11 NA NA NA NA #> kovesi NA 17 13 NA NA NA NA #> met 33 8 14 NA 1 NA NA #> misc 5 NA NA NA 3 NA NA #> parks 22 5 3 NA NA NA NA #> poly 9 NA NA NA NA NA NA #> scico NA 18 14 NA 2 NA 1 #> seaborn 6 4 2 NA NA NA NA #> stevens NA NA NA 5 NA NA NA #> tableau 29 23 28 NA NA NA NA #> tol 7 7 3 NA NA NA NA #> viridis NA 7 1 NA NA NA NA #> wes 18 NA 1 NA NA NA NA
What palettes are available, e.g diverging from the hcl series?
# Diverging palettes from the 'hcl' series c4a_palettes(type = "div", series = "hcl") #>  "hcl.blue_red1" "hcl.blue_red2" "hcl.blue_red3" "hcl.red_green" #>  "hcl.purple_green" "hcl.purple_brown" "hcl.green_brown" "hcl.blue_yellow2" #>  "hcl.blue_yellow3" "hcl.green_orange" "hcl.cyan_magenta"
Give me the colors!
# select purple green palette from the hcl series: c4a("hcl.purple_green", 11) #>  "#492050" "#82498C" "#B574C2" "#D2A9DB" "#E8D4ED" "#F1F1F1" "#C8E1C9" #>  "#91C392" "#4E9D4F" "#256C26" "#023903" # get the associated color for missing values c4a_na("hcl.purple_green") #>  "#868686"
Plot these colors:
c4a_plot("hcl.purple_green", 11, include.na = TRUE)
library(ggplot2) data("diamonds") = diamonds[diamonds$price >= 15000, ] diam_exp # discrete categorical scale ggplot(diam_exp, aes(x = carat, y = price, color = color)) + geom_point(size = 2) + scale_color_discrete_c4a_cat("carto.safe") + theme_light()
# continuous diverging scale ggplot(diam_exp, aes(x = carat, y = depth, color = price)) + geom_point(size = 2) + scale_color_continuous_c4a_div("wes.zissou1", mid = mean(diam_exp$price)) + theme_light()
c4a_guiDashboard for analyzing the palettes
c4aGet the colors from a palette (
c4a_nafor the associated color for missing values)
c4a_plotPlot a color palette
Palette names and properties:
c4a_palettesGet available palette names
c4a_seriesGet available series names
c4a_typesGet implemented types
c4a_overviewGet an overview of palettes per series x type.
c4a_citationShow how to cite palettes (with bibtex code).
c4a_infoGet information from a palette, such as type and maximum number of colors
.PEnvironment via which palette names can be browsed with auto-completion (using
Importing and exporting palettes:
c4a_dataBuild color palette data
c4a_loadLoad color palette data
c4a_sysdata_importImport system data
c4a_sysdata_exportExport system data
scale_color_continuous_c4a_divAdd scale to ggplot2.
Visual perception, in particular colors, is complex. For the purpose of information visualization it is explained in an accessible way by Ware (2019). In this vignette, we briefly describe the color spaces that are needed to understand the functionality of cols4all.
The human eye has three types of cones (specific photoreceptor cells in the retina), which are sensitive to light of different wavelengths: long, medium, and short. Their peak sensitivities (of 565, 540, and 440nm respectively) correspond to the primary colors red, green, and blue respectively. In computer graphics, a color is usually defined as RGB, which is a mixture of those three primary colors. RGB colors are often represented in hex-format (e.g. #FF00FF), where the first two characters specify red, the third and fourth green and the last two blue. Therefore #FF00FF is purple. A standard RGB space in computer graphics is sRGB (which exactly defines the primary colors, the white point, and a so-called gamma correction which is needed to perceive a grayscale linearly).
To analyse color palettes, we also use the polarLUV color space, which is a transformation of the CIELUV space. In this space, known as HCL, a color is defined by three variables:
First of all, we use the distance measure between two colors A and B from CIE as defined in 2000 (see Lindbloom, Bruce Justin. Delta E (CIE 2000).).
For simplicity, we apply two labels: colorblind friendly ☺ and colorblind unfriendly 👀. A palette without such label is classified in between. Our definition of these labels depend on the palette type:
min_dist) is the minimum distance between any two colors for any color vision deficiency type.
☺ (colorblind friendly):
min_dist >= 10
👀 (colorblind unfriendly):
min_dist <= 2
These numbers are parameters that can be changed via
min_step) is used, which is the smallest distance between any two adjacent colors (for any color vision deficiency type).
☺ (colorblind friendly):
min_step >= 5
👀 (colorblind unfriendly):
min_dist <= 1
Again, these numbers are parameters that can be changed via
c4a_options. Note that this metric is not very useful when
a continuous scale is used. In that case, it is recommended to analyse
the palette with say 7 or 9 colors.
min_stepmetric used in a similar way as for sequential palettes. In addition, the inter wing distance metric (
inter_wing_dist) is used, which is the minimum color distance between any color in the left wing to any color in the right wing of the palette (for any color vision deficiency type).
☺ (colorblind friendly):
min_step >= 5 and
inter_wing_dist >= 10
👀 (colorblind unfriendly):
min_dist <= 1 or
inter_wing_dist <= 4
These parameters can be changed via
Regarding the used hues, there is no simple good and bad. However, for quantitative palettes we distinguish
Regarding the used chroma / vividness, we label a color palette
These threshold numbers can be configured via options (to do).
Pastel (low chroma) colors are recommended for space-filling visualizations, like maps and bar charts. Vivid (high chroma) colors for small objects, such as dots, lines, and text labels.
We also use the chroma and luminance values of palette colors to find out whether some colors stand out more than other colors. Ideally, a categorical palette should contain colors that stand out about equally (for otherwise, one color will draw more attention than another, which may bias our perception and interpretation of the shown data). Colors with a high chroma value stand out more than less chromatic colors. Furthermore, against a bright background, dark colors (low luminance) stand out more, while bright colors (high luminance) stand out more against a dark background. Luminance is only considered for categorical palettes, because quantitative palettes (sequential and diverging) often map a numeric variable to luminance.
Let us define the luminance range (
Lrange) as the
maximum minus the minimum luminance value of the palette and the chroma
Crange) as the maximum chroma value minus the
minimum chroma value.
Regarding Fairness we consider two metrics: the
luminance range (
Lrange) and the chroma range
Crange). We call a palette:
Crange <= 50and (for categorical palettes only)
Lrange <= 30
Crange <= 80or (for categorical palettes only)
Lrange >= 50
Note that harmonic color palettes are usually not color blind friendly. Furthermore, when the luminance values of the colors are about equal, the contrast of those colors is low, which requires the use of border lines (see below).
The border between two colored shapes appears wobbly when the colors are equally luminant (bright), no matter what hue (red, blue, etc.) they have. This visual illusion is called equiluminance.
The contrast ratio is a measure for equiluminance,
CR = (L1 + 0.05) / (L2 + 0.05), where
L2 are the luminances (normalized
between 0 and 1) of the lighter and darker colors, respectively. Note
that the minimum contrast ratio is 1 and the maximum 21.
In the overview table, there are three flags that indicate low
CR < 1.2):
The go-to solution to prevent wobbly borders is by using black or white (depending of the lightness of the colors) border lines.
Pure blue colors, by which we mean a 0 or very low number for the R (red) and G (green) channels and a high number for the B (blue) channel may cause a visual illusion called chromostereopsis. This effect is especially prominent when blue objects are shown next to red objects against a black background.
The table column “3D Blues” indicates when a palette contains a pure blue color. The used symbol is B7#9 (which refers to a music chord used in blues music).
Harrower M, Brewer CA (2003). “ColorBrewer.org: An Online Tool for Selecting Colour Schemes for Maps.” The Cartographic Journal, 40(1), 27-37.
Hvitfeldt E. (2021). paletteer: Comprehensive Collection of Color Palettes. version 1.3.0. https://github.com/EmilHvitfeldt/paletteer
Ware, C (2019). Information Visualization - Perception for Design - 4th Edition. Elsevier
Wright K (2021). pals: Color Palettes, Colormaps, and Tools to Evaluate Them. R package version 1.7, https://CRAN.R-project.org/package=pals.