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? Thanks in advance for your help! -- View this message in context: http://r.789695.n4.nabble.com/plotting-many-unique-colors-with-categorical-data-tp3721807p3721807.html Sent from the R help mailing list archive at Nabble.com.
That's far too many to easily distinguish by color, especially if they need to be distinct, and not levels within a larger class. For the latter, you could get by with say 10 shades of red, 10 shades of blue, etc for related factors. But it doesn't sound like that's what you have. I don't think there's any way to create a palette of 75 distinguishable colors. If you really want to try, colors() gives you all the named colors. You can also use c() to combine several brewer palettes. One thing that I've done in similar cases (for viewing and data snooping, not for presentation), is to set up a loop through all the factor levels. Set par(ask=TRUE), and for each iteration plot all the points in black, except make that level a brighter color, and maybe larger symbol. It gives you a quick way to start to see the differences between groups, though obviously isn't suitable for publication. Sarah On Fri, Aug 5, 2011 at 1:46 PM, SavageMaDaMe <rloiselle at usgs.gov> 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? > > Thanks in advance for your help! >-- Sarah Goslee http://www.functionaldiversity.org
If you go to color brewer (http://colorbrewer2.org/) they don't have any color sequences above about 12 to provide separation. 75 is probably way too many, especially considering that a portion of the population is color blind and other can not see some of the gradations. You can create a pallet with 100 gradations so you can get an idea of what the spread is, but don't try to determine what an exact value is from the colors. You might try out Edward Tufte's site (http://www.edwardtufte.com/tufte/) to get an idea on how to visualize data. On Fri, Aug 5, 2011 at 1:46 PM, SavageMaDaMe <rloiselle at usgs.gov> 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? > > Thanks in advance for your help! > > -- > View this message in context: http://r.789695.n4.nabble.com/plotting-many-unique-colors-with-categorical-data-tp3721807p3721807.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
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