n_sims <- 100
n_years <- 50
ssb_low <- matrix(NA, n_years, n_sims)
ssb_high <- matrix(NA, n_years, n_sims)
catch_low <- matrix(NA, n_years, n_sims)
catch_high <- matrix(NA, n_years, n_sims)
for (i in 1:n_sims) {
sim_l <- run_simulation(scenario_low$params, F_series = ref_low$Fmsy, seed = i)
sim_h <- run_simulation(scenario_high$params, F_series = ref_high$Fmsy, seed = i)
ssb_low[, i] <- sim_l$SSB
ssb_high[, i] <- sim_h$SSB
catch_low[, i] <- sim_l$Catch
catch_high[, i] <- sim_h$Catch
}
ssb_low_df <- data.frame(
Year = rep(1:n_years, times = n_sims),
Sim = rep(1:n_sims, each = n_years),
SSB = as.vector(ssb_low) / 1e9,
Scenario = "h=0.6"
)
ssb_high_df <- data.frame(
Year = rep(1:n_years, times = n_sims),
Sim = rep(1:n_sims, each = n_years),
SSB = as.vector(ssb_high) / 1e9,
Scenario = "h=0.9"
)
ssb_df <- rbind(ssb_low_df, ssb_high_df)
median_df <- rbind(
data.frame(Year = 1:n_years, SSB = apply(ssb_low, 1, median) / 1e9, Scenario = "h=0.6"),
data.frame(Year = 1:n_years, SSB = apply(ssb_high, 1, median) / 1e9, Scenario = "h=0.9")
)
bmsy_df <- data.frame(
Scenario = c("h=0.6", "h=0.9"),
Bmsy = c(ref_low$Bmsy, ref_high$Bmsy) / 1e9
)
scenario_colors <- c("h=0.6" = "blue", "h=0.9" = "red")
p_mc <- ggplot(ssb_df, aes(x = Year, y = SSB, group = interaction(Scenario, Sim), color = Scenario)) +
geom_line(alpha = 0.1, size = 0.4, show.legend = FALSE) +
geom_line(
data = median_df,
aes(x = Year, y = SSB, color = Scenario),
size = 1.1,
inherit.aes = FALSE
) +
geom_hline(
data = bmsy_df,
aes(yintercept = Bmsy, color = Scenario),
linetype = "dashed",
size = 0.8,
inherit.aes = FALSE
) +
facet_wrap(~ Scenario, ncol = 2, scales = "free_y") +
scale_color_manual(values = scenario_colors) +
labs(x = "Year", y = "Female SSB (Mt)", title = "Monte Carlo SSB trajectories") +
ggthemes::theme_few() +
guides(color = "none")
p_mc