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.

Memory use is reduced by compressing colormaps to fewer colors and by calling colorRampPalette only when a colormap is requested.

This report gives some suggestions/recommendations for color and then gives an example of each evaluation tool.


The appearance of color depends on:

  1. The display device (screen, paper, photocopy).
  2. The type of graphic (regions/lines).
  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.

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

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

Sequential (one hue): brewer.blues.

Rainbow: cubicl, kovesi.rainbow.

Cyclical: ocean.phase.

Categorical: brewer.paired, stepped

pal.bands(coolwarm, parula, ocean.haline, brewer.blues, cubicl, kovesi.rainbow, ocean.phase, brewer.paired(12), stepped,
          main="Colormap suggestions")
## Only 24 colors are available with 'stepped'

Functions in the pals package


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.
labs=c('alphabet','alphabet2', 'glasbey','kelly','polychrome', 'stepped', 'tol', 'watlington')
pal.bands(alphabet(), alphabet2(), glasbey(), kelly(),
  polychrome(), stepped(), tol(), watlington(), labels=labs, show.names=FALSE)

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


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")


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. Leaves of the dendrogram should not be at substantially different heights.
pal.cluster(alphabet2(), main="alphabet2")


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 along the right side?
pal.csf(parula, main="parula")


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


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:

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

cubehelix polychrome


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

What to look for:

  1. Can the value of each cell be correctly inferred 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")


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

What to look for:

  1. Are regions distinct from each other?
  2. Are county outlines visible?
  3. Are outliers identifiable within each region?
  4. Are colors identifiable in the complex area (lower left) part of the map?, n=12, main="brewer.paired")