D.1 Introduction

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:

  1. distinguishing between colors and color palettes;
  2. distinguishing different kinds of color palettes;
  3. knowing various ways of specifying colors (by name, HEX code, or RGB values);
  4. knowing corresponding ways of creating new color palettes;
  5. knowing how to create or choose color palettes for people with color-vision impairments;
  6. finding R 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 "red" or "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 (Neth & Gradwohl, 2020) 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 pal_seeblau:

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:

  1. Distinguish between categorical groups;

  2. Distinguish between continuous values;

  3. 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:

  1. Use qualitative color scales to distinguish between categorical groups.

  2. Use sequential or diverging color scales to distinguish between continuous values;

  3. 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. (2020). unikn: Graphical elements of the University of Konstanz’s corporate design. Retrieved from https://CRAN.R-project.org/package=unikn