Abstract

The purpose of the pals package is twofold: (1) provide a comprehensive collection of color palettes and colormaps (2) provide tools for evaluating these collections. This report gives some suggestions/recommendations for color and then gives an example of each evaluation tool.

Recommendations

The appearance of color depends on (1) the display device (screen, paper, photocopy), (2) the type of graphic (regions/lines), and (3) the person (age, gender, colorblindness)–it is difficult to give definitive recommendations for the best palettes and colormaps. Nonetheless, here are some we like (among many!).

Diverging: coolwarm/warmcool avoid Mach banding in the middle.

Sequential: ocean.haline, parula (default in Matlab).

Rainbow: cubicl, kovesi.rainbow.

Cyclical: ocean.phase.

Categorical: brewer.paired, stepped

require(pals)
## Loading required package: pals
pal.bands(coolwarm, parula, ocean.haline, cubicl, kovesi.rainbow, ocean.phase, brewer.paired(12), stepped,
          main="Colormap suggestions")
## Only 20 colors are available with 'stepped'

Functions in the pals package

pal.bands()

Show palettes and colormaps as colored bands

What to look for:

  1. A good discrete palette has distinct colors.

  2. A good continuous colormap does not show boundaries between colors. The palette is poor, showing bright lines at yellow, cyan, pink.

labs=c('alphabet','alphabet2', 'glasbey','kelly','pal36', 'stepped', 'tol', 'watlington')
op=par(mar=c(0,5,3,1))
pal.bands(alphabet(), alphabet2(), glasbey(), kelly(),
  pal36(), stepped(), tol(), watlington(), labels=labs, show.names=FALSE)

par(op)
pal.bands(coolwarm, viridis, parula, n=200)

pal.channels()

Show the amount of red, green, blue, and gray in colors of a palette. The gray line corresponds to luminosity.

What to look for:

  1. Sequential data should usually be shown with a colormap that is smoothly increasing in lightness, as shown by the gray line.
pal.channels(parula, main="parula")

pal.cluster()

Show a palette with heirarchical clustering

The palette colors are converted to LUV coordinates before clustering.

What to look for:

  1. Colors that are visually similar tend to be clustered together.

  2. Are the leaves at substantially different heights?

pal.cluster(alphabet2(), main="alphabet2")

pal.csf()

Show a colormap with a Campbell-Robson Contrast Sensitivity Chart.

In a contrast sensitivity figure as drawn by this function, the spatial frequency increases from left to right and the contrast decreases from bottom to top. The bars in the figure appear taller in the middle of the image than at the edges, creating an upside-down “U” shape, which is the “contrast sensitivity function”. Your perception of this curve depends on the viewing distance.

What to look for:

  1. Are the vertical bands visible across the full vertical axis?

  2. Do the vertical bands blur together?

pal.csf(parula, main="parula")

pal.compress()

Many colormap functions are defined with more colors than needed. This function compresses a colormap function down to a small-ish vector of colors that can be passed into colorRampPalette to re-create the original palette with a just-noticeable-difference.

How effective is pal.compress? Compressing all 50 kovesi.* colormaps reduces memory from 352000 to 46000 bytes, a savings of 87%.

In the figure below, the top band is the coolwarm colormap function with 255 colors. The cool2 vector has 13 colors (shown at the bottom) which can be passed into the colorRampPalette function and expanded to 255 colors shown in the middle band. The maximum squared LUV distance between the individual colors in the two bands is 2.08, which is smaller than the theoretical perceptual difference.

# smooth palettes usually easy to compress
p1 <- coolwarm(255)
cool2 <- pal.compress(coolwarm)
p2 <- colorRampPalette(cool2)(255)
pal.bands(p1, p2, cool2,
  labels=c('original','compressed', 'basis'), main="coolwarm")

pal.maxdist(p1,p2) # 2.08
## [1] 2.07927

pal.cube()

The palette is converted to RGB or LUV coordinates and plotted in a three-dimensional scatterplot. The LUV space is probably better, but it is easier to tweak colors by hand in RGB space.

What to look for:

A good palette has colors that are spread somewhat uniformly in 3D.

#pal.cube(cubehelix)
#pal.cube(pal36())

cubehelix pal36

pal.heatmap()

A random heatmap is generated (with 5% missing values) and a key is added to the heatmap by appending a blank column and then a column with the palette colors.

What to look for:

  1. Can the value of each cell be correctly interpreted using the key on the right side?

  2. Can missing values be identified?

op <- par(mfrow=c(1,2), mar=c(1,1,2,2))
pal.heatmap(alphabet, n=26, main="alphabet")
pal.heatmap(alphabet2, n=26, main="alphabet2")

par(op)

pal.map()

Display a palette on a choropleth map similar to the ColorBrewer website.

What to look for:

  1. Are regions distinct from each other? Are county outlines visible?

  2. Are outliers identifiable within each region?

  3. Are colors identifiable in the complex area (lower left) part of the map.

pal.map(brewer.paired, n=12, main="brewer.paired")