# D Using colors in R

Using colors is one of the most powerful ways to structure information. Whereas understanding the concept of color is an ambitous endeavor — involving various arts, humanities, and sciences — using colors effectively requires knowledge, creativity, and experience (e.g., in choosing or creating appropriate color scales).

While this is easily the most colorful chapter of this book, defining and selecting colors in R can seem rather dull or technical. Thanks to its integrated graphics and grDevices packages, any installation of R comes fully-loaded with colors and tools for manipulating them. This means that most users of R do not need to understand the details of color theory to create beautiful visualizations. However, to efficiently find, choose, and combine colors, we need to know where to look and in which ways colors are represented in R.

This appendix provides a primer on finding, choosing, and using colors in R. A deeper knowledge about the range of color options in R directly complements the chapter on Visualizing data (see Chapter 2), but is also useful in itself.

As this chapter focuses on the practical aspects of choosing and defining colors in R, we side-step the fundamental theoretical issues surrounding the nature and perception of colors. (Consult the Wikipedia articles on Color and Color vision for an introduction and links, and read Fabio Crameri, Shephard, & Heron, 2020 for an excellent overview of using and misusing color in science communication.)

#### Disclaimer

This chapter uses the unikn package for easily displaying and modifying color palettes. This is less motivated by its functionality (though see Section D.4.3) than by our familiarity with it. Whereas its color palettes are used throughout this book, it is mostly used for its seecol() and usecol() functions here. As unikn is imported when installing the ds4psy package, there is no need for installing it separately.

### References

Crameri, Fabio, Shephard, G. E., & Heron, P. J. (2020). The misuse of colour in science communication. Nature Communications, 11(1), 1–10. https://doi.org/10.1038/s41467-020-19160-7
Neth, H., & Gradwohl, N. (2022). unikn: Graphical elements of the University of Konstanz’s corporate design. Retrieved from https://CRAN.R-project.org/package=unikn