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

Connected

Exercise

Modifying stat_smooth

In the previous exercise we used se = FALSE in stat_smooth() to remove the 95% Confidence Interval. Here we'll consider another argument, span, used in LOESS smoothing, and we'll take a look at a nice scenario of properly mapping different models.

Instructions 1/3

undefined XP
  • 1

    Explore the effect of the span argument on LOESS curves. Add three smooth LOESS stats, each without the standard error ribbon.

    • Color the 1st one "red"; set its span to 0.9.
    • Color the 2nd one "green"; set its span to 0.6.
    • Color the 3rd one "blue"; set its span to 0.3.
  • 2

    Compare LOESS and linear regression smoothing on small regions of data.

    • Add a smooth LOESS stat, without the standard error ribbon.
    • Add a smooth linear regression stat, again without the standard error ribbon.
  • 3

    LOESS isn't great on very short sections of data; compare the pieces of linear regression to LOESS over the whole thing.

    • Amend the smooth LOESS stat to map color to a dummy variable, "All".