Session Ready
Exercise

Overplotting 2: Aligned values

Let's take a look at another case where we should be aware of overplotting: Aligning values on a single axis.

This occurs when one axis is continuous and the other is categorical, which can be overcome with some form of jittering.

In the mtcars data set, fam and fcyl are categorical variants of cyl and am.

Instructions 1/3
undefined XP
  • 1
    • Create a base plot plt_mpg_vs_fcyl_by_fam of fcyl by mpg, colored by fam.
    • Add a points layer to the base plot.
    • 2

      Add some jittering by using position_jitter(), setting the width to 0.3.

    • 3

      Alternatively, use position_jitterdodge(). Set jitter.width and dodge.width to 0.3 to separate subgroups further.