1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Data Visualization with ggplot2

Connected

Exercise

Preparations

In the following exercises, we'll aim to make the plot shown in the viewer. Here, we'll establish our positions and base layer of the plot.

Establishing these items as independent objects will allow us to recycle them easily in many layers, or plots.

  • position_jitter() adds jittering (e.g. for points).
  • position_dodge() dodges geoms, (e.g. bar, col, boxplot, violin, errorbar, pointrange).
  • position_jitterdodge() jitters and dodges geoms, (e.g. points).

As before, we'll use mtcars, where fcyl and fam are proper factor variables of the original cyl and am variables.

Instructions 1/2

undefined XP
    1
    2
  • Using these three functions, define these position objects:
  • posn_j: will jitter with a width of 0.2.
  • posn_d: will dodge with a width of 0.1.
  • posn_jd will jitter and dodge with a jitter.width of 0.2 and a dodge.width of 0.1.