Exercises

  1. What geoms would you use to draw each of the following plots?
  • Scatterplot: geom_point()
  • Line Chart: geom_line()
  • Histogram: geom_histogram()
  • Bar Chart: geom_bar(stat = "identity")
  • Pie Chart: geom_bar(width = 1, stat = "identity") + coord_polar(theta = "y")

  1. Differences between geom_path() and geom_polygon()
  • geom_path() connects points in the order they appear.
  • geom_polygon() connects points and closes the shape by linking the last point back to the first.

  1. Differences between geom_path() and geom_line()
  • geom_line() connects points in order of x values.
  • geom_path() follows the exact order of points in the dataset.

  1. Low-level geoms used in composite geoms
  • geom_smooth(): Uses geom_line() and geom_ribbon().
  • geom_boxplot(): Uses geom_segment() and geom_rect().
  • geom_violin(): Uses geom_density_ridges().