[R] plotting many unique colors with categorical data
Jim Lemon
jim at bitwrit.com.au
Sat Aug 6 13:53:16 CEST 2011
On 08/06/2011 03:46 AM, SavageMaDaMe wrote:
> Hi- I am trying to plot a matrix of categorical values across time using
> color to represent each individual factor. For example:
>
> 1982 1983 1984 1985 1986 1987
> 1 19 19 68 68 19 19 68
> 2 68 68 19 19 68 68 19
> 3 26 26 34 34 26 26 26
> 4 57 34 57 57 34 57 34
> 5 34 57 26 26 57 34 57
> 6 28 28 28 28 28 58 58
> 7 60 10 58 58 58 28 28
> 8 58 58 42 27 10 39 39
> 9 22 39 22 42 42 27 42
> 10 39 22 10 39 39 20 10
>
>
> I have 75 factors which could be in different positions through out time
> (26 years). I've successfully created a plot using both ggplot() and
> color2D.matplot(), but can not select enough distinct colors from the
> default color palettes available to be able to view differences in the data.
> I've tried messing with RGB values, Brewer palettes, etc.
>
> How can I select colors from a list of available colors without choosing
> ones which are too close in similarity to each other. For instance, I could
> have several very similar blues, but if the Hue or saturation was different
> on each, it would be fairly easy to tell the difference?
>
> Maybe there are too many factors to make this visual representation
> effective?
>
Hi SavageMaDaMe,
You may be right there. The default behavior of color2D.matplot is to
scale the colors to the values. That is okay for generating a plot that
tells you, "there's a lot of green there and it gets red up in the right
corner". Not so good for identifying individual values. You can pass
explicit colors with the "cellcolors" argument, but 75 distinct colors
is a bit of a challenge. The "show.values" argument allows you to
display the values in each cell, thus identifying the factor, but you
may not want that.
I guess your idea of using different hues and saturations might work -
the light primaries (red, green, blue), a few distinguishable
intermediates (orange, yellow, aqua, purple) and gray, and you're up to
40 with five saturations for each. There have been some good papers in R
News/R Journal on color, might want to look there.
Jim
More information about the R-help
mailing list