Polychrome: Plots of Many Colors

Kevin R. Coombes

In this vignette, we describe how to use the palettes that ship with the Polychrome package. We also describe the tools that are provided to view palettes in different settings and different kinds of plots.

Getting Started

As usual, we start by loading the package:

library(Polychrome)

Next, we can look at one of the color palettes it provides.

mypal <- kelly.colors(22)
swatch(mypal)

Resorted barplots

To get a better idea of whether colors are distinguishable, we can sort them by hue:

swatchHue(mypal)

or by luminance:

swatchLuminance(mypal)

or in random order:

ranswatch(mypal)

Scatter Plots

Some colors that work well in barplots may work less well in scatter plots. To test that possibility, we can generate some random points and plot them. The next line of code generates 14 points from each color in the “alphabet” palette.

pal2 <- alphabet.colors(26)
ranpoints(pal2, 14)

Our standard way to think about colors is in the L*u*v* color space model defined by the CIE. The next plot shows how the points in the palette are distributed in the u-v subspace.

uvscatter(pal2)

We can also show the associated luminance, L.

luminance(pal2)

Plotting Curves

We can also test if a palette is useful for drawing a graph full of different curves rarther than points.

rancurves(pal2)

Color Similarity

We use L*u*v* color space because perceptual distinguishability seems to be closely related to Euclidean distance in this space. To get another view of which colors are most similar, we can perform hierarchical clustering of colors using this representation.

plothc(pal2)

We can also perform principal components in L*u*v* space to display a projectionm that tries to preserve distances.

plotpc(pal2)

Grayscale

One further consideration that should be kept in mind when creating color palettes is that not every potential viewer has normal color vision. One way to test if a color palette will remain useful in this context is to convert it to gray scale. We do this by converting to grayscale using the desaturate function fromth colorspace package, and then preparing a barplot by luminance.

grayed <- colorspace::desaturate(pal2)
swatchLuminance(grayed)