Colors

1 Objective

The viewer will be able to choose sequential, diverging and qualitative color palettes for maps using the colorspace package.

2 Introduction

Your efforts will garner more views if you make the content accessible. Colors can be an important part of the effort because colorblindness affects about 8% of males and .5% of females. Government sponsored content requires that accessibility standards be met. For example, accessibility is required by law for all (U.S.) federal information and communication technology products with a few minor exceptions.(GSA 18F, 2024). The European Union adopted web accessibility standards in 2016 which became effective in 2021.(European Union, 2016) The premier standard for accessibility is the Web Content and Accessibility Guidelines.(Web Content Accessibility Guidelines (WCAG) 2.0, 2008) The bottom line is that there are “colorblind friendly” palettes available and they should be used.

3 Packages

Users should select a color palette from a proven package. The overwhelming consensus is that those lacking design experience should “instead draw from preconstructed ramps.” (Smart et al., 2020) The good news is that “automatically generated color ramps” can perform at least as well as designer ramps in many circumstances. (Smart et al., 2020) Several excellent packages are available: RColorBrewer, colorspace and rcartocolor to name a few. There are also a couple of packages that aggregate palettes: pal and paletteer.

4 In General

In addition to the previous discussion on map aesthetics, some basic color observations are in order. An appropriate color selection should accomplish three things. First, the colors should not be unappealing. (Zeileis et al., 2019) Large areas of highly saturated colors should be avoided as viewers quickly tire and it can cause after-image effects.(Zeileis et al., 2019) Second, the colors should “cooperate” with each other, meaning that any one color should both be appealing by itself and when viewed with the others. (Zeileis et al., 2019) Third, “the colors should work everywhere”. (Zeileis et al., 2019) The colors should be distinguishable regardless of how they are displayed. The plot should convey the same meaning if it’s shown on a projector, a computer screen or a facsimile.

5 Palette Types

Colors are organized in three ways depending on the data type:

  • Qualitative palettes are used for categorical data “where no particular ordering of catgories is available and every color should receive the same perceptual weight.”

  • Sequential palettes are used for “coding ordered/numeric information where colors go from high to low or vice versa.”

  • Diverging palettes are “designed for coding numeric information around a central neutral value.” Their use shows contrasts between two extremes.

6 Colorspace

Here, we will limit the number of palettes. The color palettes within the colorspace package will be the default and we will try to limit colors to only 5 or so on the maps. If you’d like to view all of the palettes, you can run hcl_palettes(plot = T).

7 Palettes

Figure 1: Qualitative color palettes from within the colorspace package.
Figure 2: Sequential (single-hue) color palettes from within the colorspace package.
Figure 3: Sequential (multi-hue) color palettes from within the colorspace package.
Figure 4: Divering color palettes from within the colorspace package.

8 ggplot2

Within the ggplot2 framework, the colorspace syntax follows the form: “<scale_<aesthetic>_<datatype>_<colorscale>(), where <aesthetic> is the name of the aesthetic (fill, color, colour), <datatype> is the type of the variable plotted (discrete or continuous) and <colorscale> sets the type of the color scale used (qualitative, sequential, diverging, divergingx).”

scale_fill_discrete_qualitative(palette = "Pastel1")
scale_fill_continuous_sequential(palette= "Greens 2")
scale_fill_continuous_sequential(palette= "Sunset", rev = T)
scale_fill_continuous_diverging(palette = "Tropic")

Four examples of colorspace palette applied to the sf nc dataset. ‘A’ is a ‘Pastel 1’ palette applied to a qualitative variable; ‘B’ is a ‘Greens 2’ palette applied to a continuous variable; ‘C’ is the ‘Sunset’ multi-hue palette applied to a continuous variable; and ‘D’ is a the diverging palette ‘Tropic’ applied to a continuous variable.

Four examples of colorspace palette applied to the sf nc dataset. ‘A’ is a ‘Pastel 1’ palette applied to a qualitative variable; ‘B’ is a ‘Greens 2’ palette applied to a continuous variable; ‘C’ is the ‘Sunset’ multi-hue palette applied to a continuous variable; and ‘D’ is a the diverging palette ‘Tropic’ applied to a continuous variable.

9 Key Points

  • Choose color ramps from proven packages

  • colorspace is the preferred package for all color requirements

  • Qualitative palettes are used for categorical data

  • Sequential palettes are used for ordered/numeric information

  • Diverging palettes show contrasts between two extremes

  • In ggplot2, the syntax is <scale_<aesthetic>_<datatype>_<colorscale>()


European Union. (2016). Directive (EU) 2016/2102 of the European Parliament and of the Council of 26 October 2016 on the accessibility of the websites and mobile applications of public sector bodies (Text with EEA relevance ). In EUR-Lex: Access to European Union Law. https://eur-lex.europa.eu/eli/dir/2016/2102/oj
GSA 18F. (2024). US Web Accessibility Guidelines. https://guides.18f.gov/accessibility/
Smart, S., Wu, K., & Szafir, D. A. (2020). Color Crafting: Automating the Construction of Designer Quality Color Ramps. IEEE Transactions on Visualization and Computer Graphics, 26(1), 1215–1225. https://doi.org/10.1109/TVCG.2019.2934284
Web Content Accessibility Guidelines (WCAG) 2.0. (2008). https://www.w3.org/TR/WCAG20/#visual-audio-contrast
Zeileis, A., Fisher, J. C., Hornik, K., Ihaka, R., McWhite, C. D., Murrell, P., Stauffer, R., & Wilke, C. O. (2019). Colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes (arXiv:1903.06490). arXiv. https://doi.org/10.48550/arXiv.1903.06490