[R] rainbow producing colors that do not differ sufficiently

Fisher Dennis fisher at plessthan.com
Wed Mar 6 18:09:49 CET 2013


R 2.15.2
OS X

Colleagues,

I often use rainbow to select colors.  I encountered a surprise with rainbow(11).   It yielded three greens (in positions 4-6).  The first two of these are quite similar.  The man pages suggest that this might be the case:
	equispaced hues in RGB space tend to cluster at the red, green and blue primaries

The following code illustrates the problem -- the colors labeled 4 and 5 are quite similar.
	plot(1, type="n", xlim=c(1, 10), ylim=c(0, 1), axes=F, xlab="", ylab="")
	for (which in 3:7)	
		{
		rect(which - 1, 0, which, 1, border=NA, col=rainbow(11)[which])
		text(which - 0.5, 0.8, which)
		text(which - 0.5, 0.2, rainbow(11)[which], srt=90)
		}

In this case, I overcame the problem by replacing one element on the rainbow vector with a different green.  

Is there some better approach to this by which I could automate the entire process but prevent this similarity of colors?

Dennis

Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.com



More information about the R-help mailing list