In-Class Exercise 11
Shih Chien University
2026-08-03
Make a horizontal boxplot of highway fuel economy by vehicle class from mpg in two ways:
ggplot(mpg, aes(class, hwy)) + geom_boxplot() + coord_flip()ggplot(mpg, aes(hwy, class)) + geom_boxplot() (swap the aesthetics)Write one sentence confirming whether the two plots look the same, and one more explaining when coord_flip() is still needed (e.g., for geoms or stats that only work in one orientation).
Turn a bar chart into a pie chart using polar coordinates. Start from a stacked bar of drv in mpg:
Also try coord_polar() with the default theta = "x" to get a bullseye chart. Write one sentence on why the pie chart is just a stacked bar chart in a different coordinate system, and one on why bars are usually easier to read accurately than pie slices.
Using mpg, facet displ vs hwy by two variables with facet_grid(drv ~ cyl), then by one variable with facet_wrap(~class, scales = "free_y").
Write two sentences: (1) what does facet_grid() give you that facet_wrap() does not (a full 2-D grid with shared row/column labels), and (2) what is the danger of scales = "free" when your goal is comparing values across panels?
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 ex11-[StudentID].pdf, and upload it to the course pCloud folder before midnight of the following week.
ggplot2: Elegant Graphics for Data Analysis