Skip to main content

Week 4 In-Class Exercises: Data Visualization with ggplot2

GPH-GU 2182 · Fall 2026 · Paired Programming

Author

YOUR NAME & PARTNER NAME

Published

September 23, 2026

NoteInstructions

Work in pairs. One person types (driver), the other reviews and advises (navigator). Swap roles halfway through!

  • 📥 Download week-04-inclass.qmd to open and edit in RStudio (or use the </> Source Code button at the top right).
  • Render this Quarto document to HTML and push it to your GitHub repository by the end of class for participation credit.
library(ggplot2)

1 Exercise 1: Environmental Air Quality Scatterplot (Cycle 1)

Using the built-in airquality dataset, visualize the relationship between solar radiation and ozone concentrations.

# 1. Create a scatterplot of Solar.R (x) vs Ozone (y)
# 2. Map Wind speed to the point color aesthetic
# 3. Set alpha = 0.7 and size = 3 outside aes()
# 4. Add a smooth trendline with geom_smooth(method = "loess", color = "darkblue")

2 Exercise 2: Comparing Ozone Across Summer Months (Cycle 2)

Compare the distribution of ozone levels across the five summer months (May = 5 through September = 9).

# 1. Build a violin plot comparing Ozone across Months (x = factor(Month), y = Ozone)
# 2. Fill the violins by factor(Month) with alpha = 0.5
# 3. Overlay a boxplot inside the violins with width = 0.2 and fill = "white"
# 4. Suppress duplicate outlier points on the boxplot using outlier.shape = NA

3 Exercise 3: Small Multiples with facet_wrap (Cycle 3)

Examine how the temperature-ozone relationship changes month by month.

# 1. Create a scatterplot of Temp (x) vs Ozone (y)
# 2. Add points with alpha = 0.6
# 3. Add a linear regression line using geom_smooth(method = "lm", color = "red", se = FALSE)
# 4. Facet by Month into a single row using facet_wrap(~ Month, nrow = 1)

4 Exercise 4: Publication-Ready Polishing (Cycle 4 + AI Corner)

Take the multi-panel temperature plot from Exercise 3 and polish it to publication standards.

# 1. Map Wind speed to color using scale_color_viridis_c(option = "viridis")
# 2. Add complete titles, subtitle, axis labels, and caption
# 3. Apply theme_minimal() and position the legend at the bottom