Salmon Analysis Introduction

Salmon are an incredibly vital part of ecosystems all over the world, due to their natural lifecycles.

Salmon hatch from eggs in freshwater streams, where they live in for between 5 months and 2 years, depending on the species. The fish then swim downstream to the ocean, where they live for the majority of their lives. After around 7 years in the ocean, salmon will swim upstream back to the exact river where they were hatched, reproducing on the journey to reset a new generation by laying a new hatch of eggs. After laying eggs, the salmon continue to swim upstream until they die, where their bodies will decay, releasing essential nutrients into the rivers and riverbeds where they lie.

I hope to answer the questions of how salmon populations have fluctuated over time, and which species’ populations have risen and which have dropped? I also hope to tie in my findings to any historical community efforts or detriments that may have influenced those populations.

Inital Plot of Salmon Escapement Data

library(ggplot2)
salmon_data <- read.csv("~/Downloads/WDFW-Salmonid_Population_Indicators__SPI__Escapement.csv")

ggplot(salmon_data, aes(x = Year, y = Abundance.Quantity, color = Species, group = Species)) +
  geom_point(size = .25) +
  labs(title = "Escapement Estimates over Time by Species",
       x = "Year",
       y = "Escapement Estimate",
       color = "Species") 
## Warning: Removed 886 rows containing missing values or values outside the scale range
## (`geom_point()`).

This data produces an interesting visual, but it’s also quite hard to read. We are trying to compare 8 different species of fish, and because Pink salmon have such high escapement rates compared to the other 7 species, the graph becomes jumbled for all of the grouped values.

We can try to solve this problem by creating separate graphs for each species, as well as by using an interactive Plotly graph, which allows us to see specific values within the plots.

Total Abundance for Salmon Species over Time

#Splitting the plot into individual graphs for each species
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggplot2)

salmon_data <- read.csv("~/Downloads/WDFW-Salmonid_Population_Indicators__SPI__Escapement.csv")
species_pairs <- list(
  c("Cutthroat", "Bull Trout"),
  c("Sockeye", "Steelhead"),
  c("Chinook", "Coho"),
  c("Chum", "Pink")
  )

paired_plots <- lapply(species_pairs, function(pair) {
  pair_plots <- lapply(pair, function(species) {
    species_data <- subset(salmon_data, Species == species)
    plot_ly(species_data, x = ~Year, y = ~Abundance.Quantity, 
            type = 'bar', 
            name = species) %>%
    layout(
      title = paste("Abundance for Salmon species over time"), 
      xaxis = list(title = "Year"),
      yaxis = list(title = "Escapement Estimate")
    )
  })
  do.call(subplot, c(pair_plots, list(shareX = TRUE, shareY = TRUE)))
})
## Warning: Ignoring 2 observations
## Warning: Ignoring 270 observations
## Warning: Ignoring 6 observations
## Warning: Ignoring 113 observations
## Warning: Ignoring 284 observations
## Warning: Ignoring 36 observations
## Warning: Ignoring 162 observations
## Warning: Ignoring 13 observations
total_abundance_plot <- do.call(subplot, c(paired_plots, list(nrows = length(species_pairs), shareX = TRUE, shareY = TRUE)))
total_abundance_plot

Average Abundance for Salmon Species over Time

The following code computes a similar graph as the one above, however, instead of using the total abundance quantities, it now uses an esitmated average abundance value per year.

This allows for a better analysis of year to year changes, because it helps to reduce some of the error from potential inconsistent year-to-year recording.

library(plotly)
library(ggplot2)
salmon_data <- read.csv("~/Downloads/WDFW-Salmonid_Population_Indicators__SPI__Escapement.csv")

species_pairs <- list(
  c("Cutthroat", "Bull Trout"),
  c("Sockeye", "Steelhead"),
  c("Chinook", "Coho"),
  c("Chum", "Pink")
  )
ordered_species <- unlist(species_pairs)
mean_data <- salmon_data %>%
  group_by(Year, Species) %>%
  summarise(Average_Abundance = mean(Abundance.Quantity, na.rm = TRUE))
## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
mean_data$Species <- factor(mean_data$Species, levels = ordered_species)

plots <- lapply(ordered_species, function(species) {
  species_data <- subset(mean_data, Species == species)
  plot_ly(species_data, x = ~Year, y = ~Average_Abundance, 
            type = 'bar', 
            name = species) %>%
    layout(
      title = paste("Average Abundance for Salmon Species over Time"), 
      xaxis = list(title = "Year"),
      yaxis = list(title = "Average Escapement")
  )
})
average_abundance_plot <- do.call(subplot, c(plots, list(shareX = TRUE, shareY = TRUE, nrows = 4)))
## Warning: Ignoring 3 observations
## Warning: Ignoring 1 observations
## Warning: Ignoring 1 observations
## Warning: Ignoring 2 observations
## Warning: Ignoring 1 observations
## Warning: Ignoring 1 observations
## Warning: Ignoring 1 observations
average_abundance_plot

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.