Colors in ggplot

There are number of ways to control the default colors in ggplot.

The HCL Color Wheel

ggplot simplifies color choice with its default color selection, which are based on a “color wheel.”  The result is a well balanced graphic that doesn’t draw too much attention to any one color.  ggplot uses the HCL color wheel and the hue_pal() function from the scales package.  Specifically, if there are two colors, then they will be selected from opposite points on the circle; if there are three colors, they will be 120° apart on the color circle; and so on.  This ensure that discrete data has maximum contrast as a function of the number variables present.

colors in ggplot

Are Colors in ggplot Too Flashy?

The default colors in ggplot are very practical.  However, the colors sometimes look too flashy when used in certain chart types, like bar and area plots, when the colored region takes up lots of space.  To correct this, hue_pal() can be used directly to control saturation and luminosity.  Simply call the scale function scale_color_hue() for point and line charts or scale_color_fill() for bar and area charts, and use the hue_pal() arguments for hue range (h), saturation (c) and luminance  (l) as input arguments.  For example:


Back | Next