Using colors can be a powerful way of making visualizations prettier and more effective. As there is an abundance of colors, color systems, and corresponding resources, choosing colors wisely requires some restraint, as well as background knowledge on how colors can be defined, selected, and combined.
This chapter provides a colorful primer on the following topics:
- distinguishing between colors and color palettes;
- distinguishing different kinds of color palettes;
- knowing various ways of specifying colors (by name, HEX code, or RGB values);
- knowing corresponding ways of creating new color palettes;
- knowing how to create or choose color palettes for people with color-vision impairments;
- knowing many packages that provide colors and functions for dealing with color.
D.1.1 Colors vs. color palettes
Before digging any deeper into the realm of colors, it is useful to distinguish between individual colors (like
"green") and color palettes (aka. color scales or color maps), which are sets or ordered sequences of colors that somehow belong together, based on someone’s personal preference or some theoretical principle. For instance, the unikn package (Hansjoerg Neth & Gradwohl, 2019) provides the color
Seeblau, which is an individual color that can be named, perceived, and described in different ways:
It is pretty obvious that colors and color names — like “black”, “green”, or “red” — convey many different meanings and connatations. This implies that any message we want to convey in a graph not only needs to take into account the properities of the visual system perceiving a graph, but also the contextual features and semantics of the world in which the perceiver is embedded.
When combining a color with other colors, we get a color palette. For instance, the color
Seeblau occurs not only in isolation, but also as the 3rd element of the color palette
but also occurs as an element of various other color palettes:
When discussing ways of choosing or combining colors, we rarely focus on individual colors, but typically refer to color palettes. As any color palette consists out of individual colors, however, we also consider and define individual colors when addressing color palettes.
D.1.2 The functions of color
Beyond just adding some tingling sensations to our retinas and brains, color adds solid functionality to graphical represenations. But which functions do colors serve in visualizations? Apart from making graphs prettier and more pleasant to look at, we can identify 3 key functions for using color in graphs:
Distinguish between categorical groups;
Distinguish between continuous values;
Highlight graphical elements.
These 3 functions correspond to different types of color palettes.
D.1.3 Types of color palettes
As we rarely need only 1 color, we will focus on color palettes here, rather than on individual colors. Which color palette to use when depends on a range of factors (e.g., the number of distinctions to make, the number and spatial layout of elements in a graph, etc.), but we can generally map different types of color palettes to the 3 different functions:
Use qualitative color scales to distinguish between categorical groups.
Use sequential or diverging color scales to distinguish between continuous values;
Use qualitative color scales with accent colors (emphasizing the contrast between figure and ground) to highlight graphical elements.
Here are examples for these different types of color scales:
Qualitative color palettes
Sequential color palettes
Diverging color palettes
Qualitative color palettes with accent colors
When choosing a color palette for a graph, we should primarily consider the function that color serves in this particular graph. In addition, considering the semantics of individual colors and aiming for consistency with other representations typically guides and limits our options. Simultaneously satisfying many different constraints can make the selection of a color scale both challenging and intellectually stimulating.
In the following section, we show how to find and define colors and color palettes in R.
Neth, H., & Gradwohl, N. (2019). unikn: Graphical elements of the University of Konstanz’s corporate design. Retrieved from https://CRAN.R-project.org/package=unikn