[R] Colours for 3-way probabilities
Earl F Glynn
efglynn at gmail.com
Sun Dec 19 03:51:22 CET 2010
Carl Witthoft wrote:
> There are a couple Venn Diagram functions out there.
> But I would strongly recommend against making charts like this. There
> are too many colors, and even non-colorblind people will find them to be
> a pain to discriminate, let alone remember what the coding means.
> Assuming you want to show the distribution on a cartographic map, maybe
> a mini-barchart in each state or county would be better, or three
> non-overlapping 'bubbles' whose diameter or area maps to votecount.
> Tufte has written a bunch about this sort of problem.
> Are there any R functions for creating palettes for three-way data? For
> example, election maps for three parties where pure red, blue, and green
> show 100% for the Red, Blue, and Green parties respectively, magenta
> shows a 50-50 Red-Blue split with 0 for the Greens, cyan a 50-50
> Blue/Green split with no Red votes and so on, with grey, black or white
> at a 1/3,1/3,1/3 split vote.
I'm not sure that I fully understand what you're trying to do.
A chromaticity diagram conceptually shows all possible colors.
With older CRT displays, the chromaticity coordinates of the red, green
and blue phosphors on a chromaticity chart was a triangular "color
gamut" that device could display.
The gamuts of newer devices, such as LCD displays, or multi-ink printers
are a bit harder to explain, but basically could be thought of as some
sort of polygon of possible colors on a chromaticity chart. Color
coordinates outside a gamut cannot be displayed on a device.
In theory, devices can have different color gamuts. There's no
guarantee that a color outside of the gamut of a display device will be
displayed as seen on the original device.
The most common additive color primaries are red-green-blue and for
displays, it's common to use the rgb function to define colors.
See RGB color space here:
R's rgb function (?rgb) by default allows the definition of colors on a
continuum of 0.0 to 1.0 of R, G, and B primaries. E.g., red is rgb(1.0,
0.0, 0.0) and blue would be rgb(0.0, 0.0, 1.0).
So, if you're working with 0.0 to 1.0 probabilities they could be mapped
the RGB coordinates.
But the reality is that most devices are 24-bit color (ignoring the
8-bit "alpha" channel). R's rgb function can be called as rgb(255,0,0,
maxColorValue=255) to define "red", or rgb(0,0,255, maxColorValue=255)
to define "blue". Such 0:255 ranges map directly to the hardware in
This chart shows the result of fully-saturated additive RGB primary
[Also note the subtractive color primaries mentioned there.]
"Shades of gray" are produced when the R,G,B components are all the
same, e.g., rgb(0,0,0) is black and rgb(1.0, 1.0, 1.0) is white.
In theory, you could define any three additive color primaries and use a
Maxwell Triangle of the possible colors produced, e.g., with RGB:
The above discussion works well for continuous data combinations, but if
you're working with categorical data, perhaps just pick a categorical
color scheme. See: Color Schemes Appropriate for Scientific Data Graphics,
This page may be useful for picking R colors:
Or use this PDF showing R's named colors:
Besides RGB, other color spaces may be helpful for color selection and
display. Hue-Saturtion-Value coordinates can be useful with some
problems: See http://en.wikipedia.org/wiki/HSL_and_HSV and
For info on R's hsv function: ?hsv
This page shows the "hue" map of an RGB image:
See the Color Chart page above for a brief example of using R's rgb2hsv
function to convert from RGB to HSV.
Earl F Glynn
Overland Park, KS
More information about the R-help