[R] How can I create colors correspond to the number of a variable?

John McKown john.archie.mckown at gmail.com
Wed Sep 17 10:26:58 CEST 2014


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



More information about the R-help mailing list