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

Exercise

Smoothing

To practice on the remaining layers (statistics, coordinates and facets), we'll continue working on several datasets from the first course.

The mtcars dataset contains information for 32 cars from Motor Trends magazine from 1974. This dataset is small, intuitive, and contains a variety of continuous and categorical (both nominal and ordinal) variables.

In the previous course you learned how to effectively use some basic geometries, such as point, bar and line. In the first chapter of this course you'll explore statistics associated with specific geoms, for example, smoothing and lines.

Instructions 1/4

undefined XP
  • 1
    • Look at the structure of mtcars.
    • Using mtcars, draw a scatter plot of mpg vs. wt.
  • 2

    Update the plot to add a smooth trend line. Use the default method, which uses the LOESS model to fit the curve.

  • 3

    Update the smooth layer. Apply a linear model by setting method to "lm", and turn off the model's 95% confidence interval (the ribbon) by setting se to FALSE.

  • 4

    Draw the same plot again, swapping geom_smooth() for stat_smooth().