Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose n different color automatically for plotting n different objects?

I need to draw n different objects on a chart. I want to pick a different color for each of them to make them distinguishable. The objects will be moved around, so I cannot count on ideas like "four color theorem" to assign same color to non-adjacent items. So far my problem call for up to 20 different items.

Is there a good way to pick n different colors to make them as distinguishable from each other as possible?

like image 498
Wai Yip Tung Avatar asked Nov 06 '10 04:11

Wai Yip Tung


People also ask

Why do different objects show in different colors?

Objects appear different colours because they absorb some colours (wavelengths) and reflected or transmit other colours. The colours we see are the wavelengths that are reflected or transmitted.

How do I use the color function in R?

In R, colors can be specified either by name (e.g col = “red”) or as a hexadecimal RGB triplet (such as col = “#FFCC00”). You can also use other color systems such as ones taken from the RColorBrewer package.


2 Answers

First of all, I have since changed the design so that it is not important to use 20 distinct colors. The default palette of 10 colors show up quite well.

Secondly, I've found an answer to my own question. The thing I want to do is called Color scale for categorical coding. Here is a paper that propose a method to do it

An algorithm for generating color scales for both categorical and ordinal coding - Breslow - 2009 - Color Research & Application - Wiley Online Library http://onlinelibrary.wiley.com/doi/10.1002/col.20559/full

I'm going to give the paper a glance. It is probably too technical than what I prepare to do.

like image 176
Wai Yip Tung Avatar answered Oct 05 '22 19:10

Wai Yip Tung


I'd say colour distinction is a very subjective matter and you're probably better off looking for an existing colour palette and working your way from there. The higher your n, the higher your chance of two automatically generated colours being indistinguishable by your users even though by some colour-theoretic criterion they are very different.

And don't forget to make sure you don't use colour as the only distinction between objects, or:

  • you'll be in for a lot of hate mail from colour blind people
  • you risk people mistaking objects of similar colours as having some sort of implicit grouping
like image 30
chris_sutter Avatar answered Oct 05 '22 21:10

chris_sutter