Temperature and Salinity Analysis

Author

Zach Grube

Setup

library(ggplot2)
library(dplyr)
library(forcats)
temp <- read.csv(
  "C:/Users/yolom/OneDrive/Desktop/GEOG5680/Module 7/Temperature.csv",
  stringsAsFactors = FALSE,
  check.names = TRUE
)
temp <- temp %>%
  mutate(
    Year = as.factor(Year),
    Month = factor(Month, levels = 1:12, labels = month.abb),
    Station = as.factor(Station),
    Area = as.factor(Area),
    decdate = as.numeric(as.character(Year)) + dDay3 / 365
  )

Part 1

Histogram of Salinity Values

p1_salinity_hist <- ggplot(temp, aes(x = Salinity)) +
  geom_histogram(binwidth = 1, color = "white", fill = "steelblue") +
  labs(
    title = "Histogram of Salinity Values",
    x = "Salinity",
    y = "Count"
  ) +
  theme_minimal()
p1_salinity_hist

Salinity Histograms by Year

p1_salinity_by_year <- ggplot(temp, aes(x = Salinity)) +
  geom_histogram(binwidth = 1, color = "white", fill = "darkcyan") +
  facet_wrap(~ Year) +
  labs(
    title = "Salinity Histograms by Year",
    x = "Salinity",
    y = "Count"
  ) +
  theme_minimal()
p1_salinity_by_year

Salinity Histograms by Month

p1_salinity_by_month <- ggplot(temp, aes(x = Salinity)) +
  geom_histogram(binwidth = 1, color = "white", fill = "seagreen") +
  facet_wrap(~ Month) +
  labs(
    title = "Salinity Histograms by Month",
    x = "Salinity",
    y = "Count"
  ) +
  theme_minimal()
p1_salinity_by_month

Temperature Boxplot by Station

p1_temperature_boxplot <- ggplot(temp, aes(x = Station, y = Temperature)) +
  geom_boxplot(fill = "tomato", alpha = 0.75, na.rm = TRUE) +
  labs(
    title = "Temperature Values by Station",
    x = "Station",
    y = "Temperature"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
p1_temperature_boxplot

Save the Boxplot to PNG

ggsave(
  filename = "C:/Users/yolom/OneDrive/Desktop/GEOG5680/Module 7/temperature_boxplot_by_station.png",
  plot = p1_temperature_boxplot,
  width = 9,
  height = 6,
  dpi = 300
)

Bonus: Boxplot Ordered by Median Temperature

p1_temperature_boxplot_ordered <- ggplot(
  temp,
  aes(
    x = fct_reorder(Station, Temperature, .fun = median, na.rm = TRUE),
    y = Temperature
  )
) +
  geom_boxplot(fill = "goldenrod", alpha = 0.75, na.rm = TRUE) +
  labs(
    title = "Temperature Values by Station, Ordered by Median Temperature",
    x = "Station",
    y = "Temperature"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
p1_temperature_boxplot_ordered

Part 2

The decdate variable represents continuous time from the start of the observations.

temp$decdate <- as.numeric(as.character(temp$Year)) + temp$dDay3 / 365

Temperature Over Time

p2_temperature_time <- ggplot(temp, aes(x = decdate, y = Temperature)) +
  geom_point(alpha = 0.6, na.rm = TRUE) +
  labs(
    title = "Temperature Over Time",
    x = "Decimal Date",
    y = "Temperature"
  ) +
  theme_minimal()
p2_temperature_time

Salinity Over Time

p2_salinity_time <- ggplot(temp, aes(x = decdate, y = Salinity)) +
  geom_point(alpha = 0.6, na.rm = TRUE) +
  labs(
    title = "Salinity Over Time",
    x = "Decimal Date",
    y = "Salinity"
  ) +
  theme_minimal()
p2_salinity_time

Salinity Over Time by Area

p2_salinity_area_scatter <- ggplot(temp, aes(x = decdate, y = Salinity)) +
  geom_point(alpha = 0.6, na.rm = TRUE) +
  facet_wrap(~ Area) +
  labs(
    title = "Salinity Over Time by Area",
    x = "Decimal Date",
    y = "Salinity"
  ) +
  theme_minimal()
p2_salinity_area_scatter

Salinity Lineplot by Station and Area

p2_salinity_station_area_line <- ggplot(
  temp,
  aes(x = decdate, y = Salinity, color = Station, group = Station)
) +
  geom_line(na.rm = TRUE) +
  facet_wrap(~ Area) +
  labs(
    title = "Salinity Time Series by Station and Area",
    x = "Decimal Date",
    y = "Salinity",
    color = "Station"
  ) +
  theme_minimal()
p2_salinity_station_area_line

Bonus: Salinity Lineplot for Area OS

temp_os <- temp %>%
  filter(Area == "OS")
p2_salinity_os_line <- ggplot(
  temp_os,
  aes(x = decdate, y = Salinity, color = Station, group = Station)
) +
  geom_line(na.rm = TRUE) +
  labs(
    title = "Salinity Time Series by Station for Area OS",
    x = "Decimal Date",
    y = "Salinity",
    color = "Station"
  ) +
  theme_minimal()
p2_salinity_os_line