John Lekberg


Chicago Beach Water Temperatures

Created 2019-08-13.

Summertime water temperature for Chicago beaches

I used the City of Chicago's "Beach Water Quality - Automated Sensors" dataset for this graphic, which shows the summertime water temperature at the Ohio Street Beach.

I'm containing to work on the "shadow context" technique that I mentioned in my previous composition. This time, instead of showing temperature data from all years in each facet, I show the previous year's temperature data. My hope is that this facilitates year over year comparison of the water temperature at the Ohio Street Beach.

The graphic also shows the sensor coverage as a "rug" in each facet. One problem with using a line geometry like I did is that linear interpolation happens over gaps in coverage. Including the rug in the graphic allows us to notice gaps in coverage. A better solution to the line geometry problem may be to intelligently "recognize" gaps and have (potentially) multiple line segments in each facet.


Code used to create "Chicago Beach Water Temperatures"


code.r
# DATA
df %>%
  # TRANS
  filter(Beach.Name %in% c("Ohio Street Beach")) %>%
  mutate(
    Summer = case_when(
      month(Measurement.Timestamp) %in% 5:8 ~ year(Measurement.Timestamp),
      TRUE ~ NA_real_
    ),
    TimestampMDH = ymd_h(strftime(Measurement.Timestamp, "2000-%m-%d %H")),
    Water.Temperature = Water.Temperature * (9/5) + 32,
  ) %>% {
    bind_rows(
      (.) %>% mutate(
        ThisYear = FALSE,
        Summer = Summer + 1,
      ),
      (.) %>% mutate(ThisYear = TRUE),
    )
  } %>%
  filter(Summer %in% 2014:2018) %>%
  #
  {
    ggplot((.)) +
    # SCALE
    scale_color_manual(
      values = c("grey", "black"),
      labels = c("Previous Year", "Current Year"),
    ) +
    xlim(as.POSIXct("2000-06-01"), NA) +
    # COORD
    facet_grid(Summer ~ Beach.Name) +
    # GUIDE
    ggtitle(
      "Summertime Water Temperature of Chicago Beaches",
      subtitle="Previous year's temperature shown in gray. Sensor coverage shown in rug below lines."
    ) + 
    ylab("Water Temperature (degF)") +
    xlab("Date") +
    # ELEMENT
    geom_line(aes(TimestampMDH, Water.Temperature, group=ThisYear, color=ThisYear)) +
    geom_rug(aes(TimestampMDH, Water.Temperature), data = (.) %>% filter(ThisYear), sides="b") +
    # THEME
    theme_classic() +
    theme(
      legend.title = element_blank()
    )
  }