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.

Goals

This chapter aims to boost our color-related skills by introducing some related tools provided by R and R packages. More specifically:

This chapter provides a colorful primer on the following topics:

  1. distinguishing between colors and color palettes;
  2. distinguishing between different types of color palettes;
  3. knowing various ways of defining colors (by their names, HEX codes, or RGB values);
  4. finding R packages that provide colors and functions for dealing with color;
  5. creating custom color palettes for specific purposes (e.g., a particular type of graph) or audiences (e.g., for people with color-vision impairments);
  6. using color palettes (e.g., when creating visualizations in base R or ggplot2).

Overview

In the following sections, we first introduce some essential concepts (e.g., the distinction between colors and color palettes, as well as different types of color palettes), before showing various ways of finding, defining, and using colors in R:

Overall, this appendix is likely to render your future life in R much more colorful.