Get startedGet started for free

Using color

1. Using color

You just saw that the most powerful tool you have for distinguishing data values is often color. Now you'll see how to choose the best colors for your plots.

2. Colorspaces: Red-Green-Blue

How you define colors has an impact on which colors you want to choose. Many programming languages define colors by how much red, green and blue the colors contain, so the software knows how bright to make the red, green, and blue pixels onscreen. We call this the red-green-blue colorspace.

3. Colorspaces: Cyan-Magenta-Yellow-blacK

Graphic designers often define colors by the amount cyan, magenta, yellow, and black they contain because color printers have these four ink cartridges. Using this colorspace gives them the highest fidelity between what is onscreen and what is printed.

4. Choosing a plotting palette

Here's the plot of Los Angeles house prices. There are some problems with the choice of colors. Firstly, yellow points are harder to see than reds, meaning viewers might spend less time looking at the yellows, and miss important insights. Secondly, the colors blue and purple are perceptually quite close, that is, they appear to be quite similar. By contrast, yellow appears very different to the other colors. This could lead viewers of the plot to think, possibly subconsciously, that the yellow points are different to the others.

5. Colorspaces: Hue-Chroma-Luminance

The colorspace designed for data visualization is called hue-chroma-luminance, or HCL. It's designed to deal with issues of color perception. Hue is like the color of the rainbow, from red, through orange, green and blue, to purple and back to red.

6. Colorspaces: Hue-Chroma-Luminance

Chroma is the intensity of the color, from grey to a bright color. You can go from grey to bright green, or grey to bright magenta, or grey to any other hue.

7. Colorspaces: Hue-Chroma-Luminance

Luminance is the brightness of the color, from black to white. For example, you can go from black through cyan to white, or black through red to white.

8. Three types of color scale: qualitative

When choosing the colors for your plot, you can pick one of three types of color scale. Qualitative color scales are used to distinguish unordered categories, and usually involve changing the hue, while keeping chroma and luminance fixed.

9. Qualitative palette example

Here's the technology adoption line plot. The technologies are unordered, since it isn't useful to think of refrigerators as greater than stoves. Each line has a different hue, but constant chroma and luminance.

10. Three types of color scale: sequential

To emphasize ordering in your data, that is, to show that values are greater than or less than each other, you need a sequential color scale. Most sequential scales change either chroma or luminance, while keeping hue fixed.

11. Sequential palette example

Here's the fruit and vegetable consumption bar plot. The categories are ordered from zero to greater than five, so a sequential color scale makes most sense.

12. Another sequential palette example

You can also use sequential scales with continuous variables. Here's the scatter plot of life expectancy. This is slightly cheating because it uses a sequential scale that changes the hue. The color scale is called viridis, and it's designed to be easily viewable by color blind people, and to print well in black and white. This color scale had a lot of science used in its development; if you make your own sequential scale it's better to stick to changing only chroma or luminance.

13. Three types of color scale: diverging

To emphasize whether values are greater than or less than some middle value, use a diverging scale. These are similar to sequential scales, but have a neutral color like white or gray in the middle, and have increasingly bold colors with different hues on either edge.

14. Green Tech in Malaysia survey dataset

Here's another survey dataset, on green technology and recycling in Malaysia. Each question has a choice of five responses, from "Strongly Disagree" to "Strongly Agree". "Neutral" responses form a midpoint, making a diverging scale useful.

15. Diverging palette example

Here you can see each question on its own row, and the colors get bolder as the opinions get stronger.

16. Let's practice!

Let's play with some colors.