In-Class Exercise 10
Shih Chien University
2026-08-03
Every geom is a shortcut for a call to layer(). Rebuild the basic mpg scatterplot without geom_point(), spelling out the five layer components explicitly:
Write one sentence naming the five components of a layer and what role the stat plays.
Make a scatterplot of displ vs hwy with colour = class and size = cyl. Use guides() to customise the legends: show the colour legend with larger keys via guides(colour = guide_legend(override.aes = list(size = 4))), and remove the size legend entirely with size = "none".
Write one sentence on when hiding a legend is justified (e.g., the mapping is explained in the caption or is self-evident).
Explain after_stat() with a working example. Default geom_histogram() maps y to the computed variable count. Remake a histogram of diamonds$carat showing density instead:
Write two sentences: what does after_stat() do in general (it lets an aesthetic use a variable computed by the stat rather than a raw data column), and why is density on the y-axis useful when comparing groups of different sizes?
Complete your answers in the official template from the Problem sets page (author = your student ID only; keep the UUID chunk). Knit to PDF, name it ex10-[StudentID].pdf, and upload it to the course pCloud folder before midnight of the following week.
ggplot2: Elegant Graphics for Data Analysis