GGtutorial: Day 3 – Introduction to Colors

October 31, 2012

(This article was first published on is.R(), and kindly contributed to R-bloggers)

So, where does ggplot get its colors? If you’ve ever asked ggplot to color on the basis of a factor, you might have beeen surprised by the default color choices.  The fact is, ggplot colors factors on the basis of finding evenly spaced colors around the HSL color circle, shown below: EDIT: ggplot2 actually uses HCL space, which is not the same as the color circle below, but the basic idea of equally-spaced colors is valid.

So, for one color, the default is a salmon/pink color; two colors sees the addition of blue, which is found 180 degrees from the first color. For three colors, the spacing must remain even so each color is now only 120 degrees from one another, and so on. Here’s a plot that shows the color palette ggplot automatically chooses for between 1 and 8 factor levels; enjoy!

This is the output:

To leave a comment for the author, please follow the link and comment on their blog: is.R(). offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

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.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training


CRC R books series

Contact us if you wish to help support R-bloggers, and place your banner here.

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)