Generally speaking you should not spend time choosing your own color palette as there are many resources for choosing palettes of colors that “work well together” (under a variety of criteria). In R, colors may be chosen individually or as part of a larger palette. We will discuss colors more in this module.
Choosing Individual Colors
Named Colors
You can choose one of the 657 named colors in R (e.g., color="orange4"
).
Hexadecimal Colors
You can choose a color by specifying its hexadecimal code (e.g., color="#CC3300"
). Here is a more comprehensive showing of colors by hexadecimal code.
Choosing Colors as a Palette
Two simple color-blind-friendly palettes are shown below, with R code to produce a vector with the colors (from cookbook-r).
# The palette with grey:
cbPalette <- c("#999999","#E69F00","#56B4E9","#009E73",
"#F0E442","#0072B2","#D55E00","#CC79A7")
# The palette with black:
cbbPalette <- c("#000000","#E69F00","#56B4E9","#009E73",
"#F0E442","#0072B2","#D55E00","#CC79A7")
Other sources of palettes are listed below:
- Paletteer Gallery: Gallery of palettes built into R and R packages.
- Colorspace package in R: An R toolbox for manipulating and assessing colors and palettes. A demonstration for using directly in R.
- HCL Wizard: Software to develop palettes and emulate what a graph would look like to multiple types of color deficiency (i.e,. color-blindness).
- ColorBrewer 2.0: A classic method of choosing a palette.
- Color Pallette Generator: Generates a color palette from one user-provided color.
- Color Thief: Software to generate a palette from an image.
- Color Calculator: Generate color scheme by choosing base colors and a “harmony.”