## D.6 Summary

#### Colors in R

The 657 named colors() in R provide more options than most of us will ever need. And given the ability of R for specifying colors in HEX codes and RGB values, plus the recent integration of powerful HCL colors in the grDevices component of R (see hcl.colors() in R 3.6.0+), most R users can live happily without ever needing a dedicated color package.

Nevertheless, having additional options can still make our lives both simpler and more colorful (e.g., by providing a color palette that we like or need to use). Despite the rich options provided by base R, we frequently use other packages for functions that make it easier to see or modify color palettes (e.g., the seecol() and usecol() functions from unikn) or cater to more personal or exotic color preferences (e.g., the special palettes provided by the colourlovers, rijkspalette, unikn, wesanderson, or yarrr packages). Especially when publications contain many related visualizations, a well-designed color scheme can greatly improve our overall impression and convey specific messages much more clearly.

#### Lessons learned

This chapter has shown that there is an abundance of options for choosing and using colors in R:

This chapter provided 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).

Fortunately, we rarely need all these options at the same time. In my experience, remembering a handful of decent R color names and a few color-related functions covers about 80% of all use cases — and all other cases should be addressed by using color palettes designed by color experts.

#### A caveat

After discussing a plethora of options for dazzling colors, we conclude this chapter on a cautionary note: Colors can be perceived as pretty or as ugly, but choosing them wisely is not just a matter of taste, but also one of physics, biology, psychology, history, and individual and societal context. Whenever considering which color to add to a graph, we should first ask ourselves whether a particular choice of colors is suited to convey the meaning of a visual representation more transparently. Thus, when choosing and using color, we should always aim for both clarity and beauty.