wszsdmjj
2014-Sep-17 04:34 UTC
[R] How can I create colors correspond to the number of a variable?
I need to create a color vector with 4000 colors, and I have another variable, it contains 4000 element. If my variable is number of bed, and I want the color corresponds to the number of bed in this variable. How should I do? -- View this message in context: http://r.789695.n4.nabble.com/How-can-I-create-colors-correspond-to-the-number-of-a-variable-tp4697052.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
John McKown
2014-Sep-17 08:26 UTC
[R] How can I create colors correspond to the number of a variable?
First off, please post in plain text not HTML. It is a forum requirement. HTML posts are often ignored, especially if they look "messy" in plain text, which is all that the mailing list software distributes. It strips off the HTML portion entirely. Your question is vague in that you didn't indicate what you wanted in the way of colors and what you were going to do with them. For plotting? For visually distinguishing one out of 4,000 possible beds by color on a screen display? If you want plotting, then use ggplot2 and the scale_color_brewer() function: http://docs.ggplot2.org/current/scale_brewer.html . My personal opinion is that it is unlikely that an average person will be able to memorize 4,000 different colors, be able to see one of them, and say definitively "that is bed number ---". Especially if the person is even mildly color blind. Depending on use, the U.S. ADA (American with Disabilities Act) may become a factor. Companies need to remember this. Individuals, not so much. But rather than give any real opinion about this question, I will just point out some archive messages which might be of some help. https://groups.google.com/forum/#!searchin/r-help-archive/$2Br-help$20$2Bcolor/r-help-archive/yOXrLIU-S8M/jc0yRQ6tNZgJ https://groups.google.com/forum/#!searchin/r-help-archive/$2Br-help$20$2Bcolor/r-help-archive/duLEBjtqzTU/J45x_EB2BAIJ This doesn't address R, but does address the use of color, and gives a reference to the R color brewer (http://colorbrewer2.org/) http://ux.stackexchange.com/questions/17964/how-many-visually-distinct-colors-can-accurately-be-associated-with-a-separate Pantone, an industry standard in color, has 2,058 colors in their Goe inventory: http://pantone.custhelp.com/app/answers/detail/a_id/1671/related/1 This site might help you select the colors: http://www.colorsontheweb.com/ And I do know that I did not directly answer your question with a piece of code. On Tue, Sep 16, 2014 at 11:34 PM, wszsdmjj <wszsdmjj at 163.com> wrote:> I need to create a color vector with 4000 colors, and I have another > variable, it contains 4000 element. If my variable is number of bed, and I > want the color corresponds to the number of bed in this variable. How should > I do? > > > > -- > View this message in context: http://r.789695.n4.nabble.com/How-can-I-create-colors-correspond-to-the-number-of-a-variable-tp4697052.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > 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.-- There is nothing more pleasant than traveling and meeting new people! Genghis Khan Maranatha! <>< John McKown
Jim Lemon
2014-Sep-17 09:16 UTC
[R] How can I create colors correspond to the number of a variable?
On Tue, 16 Sep 2014 09:34:39 PM wszsdmjj wrote:> I need to create a color vector with 4000 colors, and I have another > variable, it contains 4000 element. If my variable is number of bed,and I> want the color corresponds to the number of bed in this variable. Howshould> I do? >Hi wszsdmjj, I assume that you have 4000 numbers of which all may be different and you want to assign colors that will represent these values along some dimension. I think that the answer that John gave is probably correct, but if not, have a look at the color.scale function in the plotrix package. Jim