2017 vs 2020 Herring M2 from North Sea SMS

Output figures comparing M2 by predator (should match Morten’s outputs)

M2_2017 <- read_csv(here("KeyRunComparisons" , "NorthSeaSMS2017", "who_eats_whom_level1.csv"))
M2_2020 <- read_csv(here("KeyRunComparisons" , "NorthSeaSMS2020", "who_eats_whom_level1.csv"))
M2_2020_old <- read_csv(here("KeyRunComparisons" , "NorthSeaSMS2020", "who_eats_whom_level1_old.csv"))

M2_2017 <- add_column(M2_2017, KeyRun = "SMS2017") 
M2_2020 <- add_column(M2_2020, KeyRun = "SMS2020")
M2_2020_old <- add_column(M2_2020_old, KeyRun = "SMS2020_old")
M2_comp <- bind_rows(M2_2017, M2_2020)
M2_comp <- bind_rows(M2_comp, M2_2020_old)

# aggregate birds
M2_comp <- M2_comp %>%
    mutate(Predator = as.character(Predator),
           Predator = ifelse(Predator %in% c("Fulmar","Gannet","GBB. Gull","Guillemot","Her. Gull","Kittiwake","Puffin","Razorbill"), "Birds", Predator)) %>%
    group_by(Year,Quarter,Predator, Predator.age,Prey, Prey.age, KeyRun) %>%
    mutate(M2 = sum(Part.M2, na.rm=T)) %>%
    ungroup()
    
# length(unique(dat3$Predator)) #http://medialab.github.io/iwanthue/
col <- c("#000047","#858a00","#ff2b47","#00d3c9", "#0188d2", "#7426d6","#e37b00","#ffa0ee","#930025","#00bd3b","yellow","black","#005144")
names(col) <- c("A. radiata", "Birds", "Cod", "G. gurnards", "Grey seal", "H. porpoise", "Haddock", "Hake", "Mackerel",  "Saithe", "Whiting", "N.horse mac", "W.horse mac") 

preycol <- c("#da62e7", "#549700", "#00609a", "#8dd971", "#535622")
names(preycol) <- as.factor(c("N. sandeel", "Nor. pout",  "S. sandeel", "Herring", "Sprat"))

col <- c(col, preycol)

M2_2017 <- M2_comp %>% filter(KeyRun %in% "SMS2017")
M2_2020 <- M2_comp %>% filter(KeyRun %in% "SMS2020")

2017 Keyrun M2 (fixed y axis)

plist = lapply(split(M2_2017, M2_2017$Prey), function(d) {
  ggplot(d, aes(Year, Part.M2, fill=Predator)) + 
    geom_bar(stat = "identity") +
    facet_wrap(Prey~Prey.age) +
    xlab("Year") +
    ylab("M2") +
    scale_fill_manual(values=col) +
    theme_tufte() +
    theme(legend.position="bottom")
})

Cod

plist$Cod

Haddock

plist$Haddock

Herring

plist$Herring

N. Sandeel

plist$'N. sandeel'

S. Sandeel

plist$'S. sandeel'

Norway pout

plist$'Nor. pout'

Sprat

plist$Sprat

Whiting

plist$Whiting

2020 Keyrun M2 (fixed y axis)

plist2 = lapply(split(M2_2020, M2_2020$Prey), function(d) {
  ggplot(d, aes(Year, Part.M2, fill=Predator)) + 
    geom_bar(stat = "identity") +
    facet_wrap(Prey~Prey.age) +
    xlab("Year") +
    ylab("M2") +
    scale_fill_manual(values=col) +
    theme_tufte() +
    theme(legend.position="bottom")
})

Cod

plist2$Cod

Haddock

plist2$Haddock

Herring

plist2$Herring

N. Sandeel

plist2$'N. sandeel'

S. Sandeel

plist2$'S. sandeel'

Norway pout

plist2$'Nor. pout'

Sprat

plist2$Sprat

Whiting

plist2$Whiting

2017 Keyrun M2 (variable y axis)

plist3 = lapply(split(M2_2017, M2_2017$Prey), function(d) {
  ggplot(d, aes(Year, Part.M2, fill=Predator)) + 
    geom_bar(stat = "identity") +
    facet_wrap(Prey~Prey.age, scales = "free_y") +
    xlab("Year") +
    ylab("M2") +
    scale_fill_manual(values=col) +
    theme_tufte() +
    theme(legend.position="bottom")
})

Cod

plist3$Cod

Haddock

plist3$Haddock

Herring

plist3$Herring

N. Sandeel

plist3$'N. sandeel'

S. Sandeel

plist3$'S. sandeel'

Norway pout

plist3$'Nor. pout'

Sprat

plist3$Sprat

Whiting

plist3$Whiting

2020 Keyrun M2 (variable y axis)

plist4 = lapply(split(M2_2020, M2_2020$Prey), function(d) {
  ggplot(d, aes(Year, Part.M2, fill=Predator)) + 
    geom_bar(stat = "identity") +
    facet_wrap(Prey~Prey.age, scales = "free_y") +
    xlab("Year") +
    ylab("M2") +
    scale_fill_manual(values=col) +
    theme_tufte() +
    theme(legend.position="bottom")
})

Cod

plist4$Cod

Haddock

plist4$Haddock

Herring

plist4$Herring

N. Sandeel

plist4$'N. sandeel'

S. Sandeel

plist4$'S. sandeel'

Norway pout

plist4$'Nor. pout'

Sprat

plist4$Sprat

Whiting

plist4$Whiting

Compare Herring M2 between 2017 and 2020

Now tabs are herring predators

# want all the birds separated out now
M2_2017 <- read_csv(here("KeyRunComparisons" , "NorthSeaSMS2017", "who_eats_whom_level1.csv"))
M2_2020 <- read_csv(here("KeyRunComparisons" , "NorthSeaSMS2020", "who_eats_whom_level1.csv"))
M2_2020_old <- read_csv(here("KeyRunComparisons" , "NorthSeaSMS2020", "who_eats_whom_level1_old.csv"))

M2_2017 <- add_column(M2_2017, KeyRun = "SMS2017") 
 M2_2020 <- add_column(M2_2020, KeyRun = "SMS2020")
 M2_2020_old <- add_column(M2_2020_old, KeyRun = "SMS2020_old")
 M2_comp <- bind_rows(M2_2017, M2_2020)
 M2_comp <- bind_rows(M2_comp, M2_2020_old)

M2_compHerring <- M2_comp %>%
  filter(Prey=="Herring") %>%
  group_by(Year, Predator, Prey, Prey.age, KeyRun) %>%
  summarise_at(vars(eatenW, Part.M2), funs(sum))

plist5 = lapply(split(M2_compHerring, M2_compHerring$Predator), function(d) {
  ggplot(d, aes(Year, Part.M2, group=KeyRun)) + 
    geom_point(aes(colour=KeyRun)) +
    geom_line()+
    facet_wrap(Prey~Prey.age, scales = "free_y", ncol = 2) +
    xlab("Year") +
    ylab("M2") +
    theme_tufte() +
    theme(legend.position="bottom")
})

Cod

plist5$Cod

Fulmar

plist5$Fulmar

G. gurnards

plist5$'G. gurnards'

Gannet

plist5$Gannet

GBB. Gull

plist5$'GBB. Gull'

Grey seal

plist5$'Grey seal'

Guillemot

plist5$Guillemot

H. porpoise

plist5$'H. porpoise'

Hake

plist5$Hake

Her. Gull

plist5$'Her. Gull'

Kittiwake

plist5$Kittiwake

Mackerel

plist5$Mackerel

N.horse mac

plist5$'N.horse mac'

Puffin

plist5$Puffin

Razorbill

plist5$Razorbill

Saithe

plist5$Saithe

Whiting

plist5$Whiting

Compare Whiting M2 between 2017 and 2020

Now tabs are whiting predators

M2_compWhiting <- M2_comp %>%
  filter(Prey=="Whiting") %>%
  group_by(Year, Predator, Prey, Prey.age, KeyRun) %>%
  summarise_at(vars(eatenW, Part.M2), funs(sum))

plist6 = lapply(split(M2_compWhiting, M2_compWhiting$Predator), function(d) {
  ggplot(d, aes(Year, Part.M2, group=KeyRun)) + 
    geom_point(aes(colour=KeyRun)) +
    geom_line()+
    facet_wrap(Prey~Prey.age, scales = "free_y", ncol = 2) +
    xlab("Year") +
    ylab("M2") +
    theme_tufte() +
    theme(legend.position="bottom")
})
preds <- unique(M2_compWhiting$Predator)

for(i in 1:length(preds)) {
  cat("  \n####",  preds[i],"  \n")
  print(plist6[preds[i]]) 
  cat("  \n")
}

A. radiata

$A. radiata

Cod

$Cod

Fulmar

$Fulmar

G. gurnards

$G. gurnards

GBB. Gull

$GBB. Gull

Grey seal

$Grey seal

Guillemot

$Guillemot

H. porpoise

$H. porpoise

Her. Gull

$Her. Gull

Kittiwake

$Kittiwake

N.horse mac

$N.horse mac

Razorbill

$Razorbill

Saithe

$Saithe

Whiting

$Whiting

Compare Sprat M2 between 2017 and 2020

Now tabs are sprat predators

M2_compSprat <- M2_comp %>%
  filter(Prey=="Sprat") %>%
  group_by(Year, Predator, Prey, Prey.age, KeyRun) %>%
  summarise_at(vars(eatenW, Part.M2), funs(sum))

plist7 = lapply(split(M2_compSprat, M2_compSprat$Predator), function(d) {
  ggplot(d, aes(Year, Part.M2, group=KeyRun)) + 
    geom_point(aes(colour=KeyRun)) +
    geom_line()+
    facet_wrap(Prey~Prey.age, scales = "free_y", ncol = 2) +
    xlab("Year") +
    ylab("M2") +
    theme_tufte() +
    theme(legend.position="bottom")
})
preds <- unique(M2_compSprat$Predator)

for(i in 1:length(preds)) {
  cat("  \n####",  preds[i],"  \n")
  print(plist7[preds[i]]) 
  cat("  \n")
}

Cod

$Cod

Fulmar

$Fulmar

G. gurnards

$G. gurnards

Gannet

$Gannet

GBB. Gull

$GBB. Gull

Guillemot

$Guillemot

Her. Gull

$Her. Gull

Kittiwake

$Kittiwake

Mackerel

$Mackerel

N.horse mac

$N.horse mac

Puffin

$Puffin

Razorbill

$Razorbill

Whiting

$Whiting

Find biggest M2 differences for age 2 herring between key-runs:

M2_diffHerring <- M2_compHerring %>%
  arrange(Year, Predator, Prey, Prey.age, KeyRun) %>% 
  group_by(Year, Predator, Prey, Prey.age) %>% 
  mutate(diffM2_2020 = c(diff(Part.M2), NA),
         diffeatenW_2020 = c(diff(eatenW), NA)) %>%
  filter(!is.na(diffM2_2020))

age2diff <- M2_diffHerring %>%
  filter(Prey.age==2) %>%
  arrange(diffM2_2020)

library(DT)
datatable(age2diff, rownames = FALSE, options = list(pageLength = 25))