Code
library(tidyverse)
library(here)
library(tsibble) #for time series analysis
library(feasts) #feature extraction and statistics for time series
library(fable)
library(patchwork)
library(janitor)January 20, 2024

Dataset & report summary: Data used in this analysis was accessed from Columbia River Data Access in Real Time (DART). Columbia River DART provides interactive data resources to support research and management practices relating to the Columbia River Basin salmon populations and overall river ecosystem. This dataset includes information on adult fish passage recorded from 2001-01-01 to 2010-12-31 at the Willamette Falls fish ladder on the Willamette River (Oregon). The following report includes a time series analysis for the data and various figures in three different parts: part 1 (original time series analysis), part 2 (season plots exploring patterns in seasonality), and part 3 (annual counts of fish passage by each species).
Data citation: Columbia Basin Research. (n.d.). Columbia River DART. Retrieved January 25, 2023, from https://www.cbr.washington.edu/dart/query/adult_graph_text
#Select the appropriate columns and pivot the data
#Convert the data frame into time series format
fish_ts <- fish_df %>%
select(project, date, coho, jack_coho, steelhead) %>%
pivot_longer(cols = 3:5,
names_to = "species", values_to = "count") %>%
mutate(date = lubridate::mdy(date)) %>%
as_tsibble(key = species,
index = date)
fish_ts_0 <- replace(fish_ts, is.na(fish_ts), 0) #replace NAs with 0passage_plot <- ggplot(fish_ts_0,
aes(x = date, y = count)) +
geom_line() +
theme_bw() +
facet_wrap(~species, labeller = labeller(species = c(
"coho" = "Coho",
"jack_coho" = "Jack coho",
"steelhead" = "Steelhead"))) +
labs(x = "Year", y = "Fish passage counts")
# scale_color_manual(values = c("coho" = "lightblue",
# "jack_coho" = "skyblue2",
# "steelhead" = "skyblue4"))
passage_plot
# passage_plot2 <- ggplot(fish_ts_0,
# aes(x = date, y = count, fill = species)) +
# geom_col() +
# theme_bw() +
# scale_fill_brewer(palette = "Dark2")
# passage_plot2
Major Trends:
Major Trends:
fish_ts_annual <- fish_df %>%
select(project, date, coho, jack_coho, steelhead) %>%
pivot_longer(cols = 3:5,
names_to = "species", values_to = "count")
fish_ts_annual_0 <- replace(fish_ts_annual, is.na(fish_ts_annual), 0)
fish_ts_annual_0 <- fish_ts_annual_0 %>%
mutate(date = lubridate::mdy(date)) %>%
mutate(year = lubridate::year(date)) %>%
mutate(Year = as.factor(year)) %>%
select(Year, species, count)
fish_count <- aggregate(count ~ Year+species, data = fish_ts_annual_0, FUN = sum)
#group_by(Year, species) %>%
#summarize(annual_count = n(), .groups = "drop")annual_count <- ggplot(fish_count, aes(x = Year, y = count, fill = species)) +
geom_col(color = "black", size = 0.1) +
labs(x = "Year",
y = "Fish passage counts") +
theme_bw() +
facet_wrap(~species, scales = "free_y", nrow = 3,
labeller = labeller(species = c("coho" = "Coho",
"jack_coho" = "Jack coho",
"steelhead" = "Steelhead"))) +
scale_fill_brewer() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(legend.position = "none") #get rid of the legend
# geom_text(aes(label = count), vjust = -0.5, size = 2) #show the column values
annual_count
Major Trends:
This assignment was created and organized by Casey O’Hara at the Bren School for ESM 244 (Advanced Data Analysis for Environmental Science & Management). ESM 244 is offered in the Master of Environmental Science & Management (MESM) program.
@online{pepperdine2024,
author = {Pepperdine, Maxwell},
title = {Time Series Analysis},
date = {2024-01-20},
url = {https://maxpepperdine.github.io/posts/2024-01-20-salmon-time-series/},
langid = {en}
}