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

Connected

Exercise

Plotting variations

The preparation is done; now let's explore stat_summary().

Summary statistics refers to a combination of location (mean or median) and spread (standard deviation or confidence interval).

These metrics are calculated in stat_summary() by passing a function to the fun.data argument. mean_sdl(), calculates multiples of the standard deviation and mean_cl_normal() calculates the t-corrected 95% CI.

Arguments to the data function are passed to stat_summary()'s fun.args argument as a list.

The position object, posn_d, and the plot with jittered points, p_wt_vs_fcyl_by_fam_jit, are available.

Instructions 1/3

undefined XP
  • 1
    • Add error bars representing the standard deviation.
      • Set the data function to mean_sdl (without parentheses).
      • Draw 1 standard deviation each side of the mean, pass arguments to the mean_sdl() function by assigning them to fun.args in the form of a list.
      • Use posn_d to set the position.
  • 2

    The default geom for stat_summary() is "pointrange" which is already great.

    • Update the summary stat to use an "errorbar" geom by assigning it to the geom argument.
  • 3
    • Update the plot to add a summary stat of 95% confidence limits.
    • Set the data function to mean_cl_normal (without parentheses).
    • Again, use the dodge position.