Know your data
Visualize your data – categorical variables
Work with your chart 2
13. Color and the ordinal variable
Check yourself 2

Instruction

Use a sequential color scale for the ordinal variable.

If you want to add color to the elements that encode the ordinal (ordering) variable, you should use a sequential color scale. It doesn't matter if this is a numerical or categorical value. In this case, the color scale should help the reader immediately sort values from lowest to highest.

In our example, the sequential scale will not only highlight that levels of consumption represent ordered categories, it will also help readers see the trend in the data. It's immediately clear that a high level of consumption (the darkest shade) increases its percentage share as the wealth category increases.

In ggplot2, you can access C. Brewer's sequential scales by using this command:

+ scale_fill_brewer(type = "seq", palette = palette_name )

The type argument sets the type of color scale (here, sequential). The palette argument sets the name of the palette. You can use the Color card to see all available sequential palettes. It's located in the right navigation tab. Take a look at the color palettes before doing the next exercise.

Exercise

Choose your own sequential scale from the Color card and apply it to our chart. Add scale_fill_brewer(type = "seq", palette = palette_name ) to the mosaicplot object. Set palette to your choice of color palette.

Stuck? Here's a hint!

You should write:

scale_fill_brewer(type = "seq", palette = "BlueGn")