Generate Distinct Colors

June 16, 2014

[This article was first published on Category: R | Huidong Tian's Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

When plot with R (or some other software), it doesn’t bother you a lot for choosing colors if you have only several data series. For example, if I want to create a figure for 5 data series, I can choose red, green, dark green, blue and black. But what if I need to create a figure having 100 data series? Of course, we can choose different shape or pattern, like dash line, circle, triage, etc. However, to me, I feel that make the figure messy, I prefer all series in same style, except their colors. I created a Shiny-app which can generate random distinct colors in a certain color plate, would like to share it with public.

The app’s address is here.

The design idea is like this:

  1. Generate N random points. Some points are very close to each other, so they are easy distinguished.
  2. Find the point-pair which have the shortest distance, pick up one point of it and put it to a new location where it has the largest distance to all the rest points.
  3. Continue the above step, until there is no new location meet.

To leave a comment for the author, please follow the link and comment on their blog: Category: R | Huidong Tian's Blog. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)