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

Connected

Exercise

Adding geometries

The diamonds dataset contains details of 1,000 diamonds. Among the variables included are carat (a measurement of the diamond's size) and price.

You'll use two common geom layer functions:

  • geom_point() adds points (as in a scatter plot).
  • geom_smooth() adds a smooth trend curve.

As you saw previously, these are added using the + operator.

ggplot(data, aes(x, y)) +
  geom_*()

Where * is the specific geometry needed.

Instructions 1/3

undefined XP
  • 1

    Explore the diamonds data frame with the str() function.

  • 2

    Edit the plot code to add a point geom. Use the + operator to add geom_point() to the ggplot() command.

  • 3

    Add a smooth geom to the plot. Use the + operator to add geom_smooth().