GGtutorial: Day 3 – Introduction to Colors
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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:
R-bloggers.com 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.