Classwork 11

Relationship Plots

Author

Byeong-Hak Choe

Published

November 7, 2025

Modified

November 6, 2025

Question 1. Ice Cream Sales and Drowning Incidents

Consider the data frame df, which records monthly ice cream sales and drowning incidents.

library(tidyverse)
df <- read_csv("http://bcdanl.github.io/data/icecream-drowning.csv")

Part A

  • πŸ€– Task 1: Fill in the blanks in the provided ggplot() code chunk.
  • πŸ’¬ Task 2: Add a brief comment describing the relationship between ice cream sales (IceCreamSales) and drowning incidents (DrowningIncidents).

ggplot(data = __BLANK_1__,
       mapping = aes(x = __BLANK_2__,
                     y = __BLANK_3__)) +
  geom___BLANK_4__() +
  geom___BLANK_5__()


Part B

  • ❓ Is the observed relationship one of correlation or causation? Explain your reasoning.
    • Consider the following monthly trends for IceCreamSales and DrowningIncidents:

Monthly Trend of IceCreamSales


Monthly Trend of DrowningIncidents



Question 2. NBC Show Data

The nbc_show dataset comes from NBC’s TV pilots, containing information about television shows, their viewership metrics, and audience engagement.

library(tidyverse)
nbc_show <- read_csv("https://bcdanl.github.io/data/nbc_show.csv")
  • Gross Ratings Points (GRP):
    Measures the estimated total viewership of a show β€” an indicator of its broadcast marketability.
    • πŸ“Ί A higher GRP suggests broader exposure and a more marketable program.
  • Projected Engagement (PE):
    Captures how attentive and engaged viewers were after watching a show β€” a more suitable measure of audience engagement.
    • 🧠 After viewing, audiences take a short quiz testing order and detail recall.
    • This reflects their level of attention and retention (for both the show and its ads).
    • High PE values indicate strong viewer engagement.


Tasks

  • πŸ€– Task 1: Fill in the blanks in the provided ggplot() code chunks.
  • πŸ’¬ Task 2: Add a brief comment describing the relationship between GRP and PE.

(1) Scatterplot with a Non-Linear Fitted Line

ggplot(data = __BLANK_1__,
       mapping = aes(x = __BLANK_2__,
                     y = __BLANK_3__)) +
  geom_point() +
  geom___BLANK_4__()


(2) Scatterplot with a Linear Fitted Line

ggplot(data = __BLANK_1__,
       mapping = aes(x = __BLANK_2__,
                     y = __BLANK_3__)) +
  geom_point() +
  geom___BLANK_4__(method = __BLANK_5__)


Question 3. GDP per capita vs. Life Expectancy

For Question 3, please install the R package gapminder before starting:

install.packages("gapminder")
??gapminder

The gapminder package provides a built-in dataset named gapminder, which contains country-level data on life expectancy, GDP per capita, and population across time.

Let’s assign it to a new object called df_gapminder:

df_gapminder <- gapminder::gapminder

Tasks

  • πŸ€– Task 1: Fill in the blanks in the provided ggplot() code chunks.
  • πŸ’¬ Task 2: Add a brief comment describing the relationship between GDP per capita (gdpPercap) and life expectancy (lifeExp).

(1) gdpPercap vs. lifeExp

ggplot(data = __BLANK_1__,
       mapping = aes(x = __BLANK_2__,
                     y = __BLANK_3__)) +
  geom_point(__BLANK_4__ = .1) + # Add transparency to reduce overplotting
  geom_smooth(__BLANK_5__ = "darkorange") +
  geom_smooth(__BLANK_6__)


(2) log(gdpPercap) vs. lifeExp

ggplot(data = __BLANK_1__,
       mapping = aes(x = __BLANK_2__,
                     y = __BLANK_3__)) +
  geom_point(__BLANK_4__ = .2) + # Add transparency to reduce overplotting
  geom_smooth(__BLANK_5__ = "darkorange") +
  geom_smooth(__BLANK_6__)


Back to top