Skip to content

Commit

Permalink
Plots for individual groups
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-rohan-NOAA committed Nov 8, 2024
1 parent 54fe68b commit 8b4c183
Show file tree
Hide file tree
Showing 48 changed files with 244 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: esrindex
Type: Package
Title: Abundance index products for Alaska ESRs
Version: 1.0.0
Date: 2024-11-01
Date: 2024-11-08
Authors@R: c(person("Sean", "Rohan", email = "sean.rohan@noaa.gov", role = c("aut", "cre")),
person("Thaddaeus", "Buser", email = "thaddaeus.buser@noaa.gov", role = "ctb"),
person("Christina", "Conrath", email = "christina.conrath@noaa.gov", role = "ctb"),
Expand Down
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
esrindex 1.0.0 (November 8, 2024) - First production release
----------------------------------------------------------------

NEW FEATURES

- plot_region_rema() makes individual timeseries plots for each
group.


esrindex 0.1.4 (October 1, 2024)
----------------------------------------------------------------

Expand Down
233 changes: 233 additions & 0 deletions R/plot_region_rema.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,239 @@ plot_region_rema <- function(x,

plot_list[[ii]] <- p1

# Plots for individual groups
for(kk in 1:length(group_name)) {

sel_group_fit <- fit_dat[fit_dat$group_name == group_name[kk], ]

sel_group_obs <- obs_dat[obs_dat$group_name == group_name[kk], ]

sel_group_ts_summary <- ts_summary[ts_summary$group_name == group_name[kk], ]

if(error_bar & benchmarks == "none") {

p1 <- ggplot() +
geom_ribbon(data = sel_group_fit,
mapping = aes(x = year,
ymin = pred_lci,
ymax = pred_uci),
alpha = 0.3,
fill = ribbon_fill) +
geom_errorbar(data = sel_group_obs,
mapping = aes(x = YEAR,
ymin = BIOMASS_PLUS2_SD,
ymax = BIOMASS_MINUS2_SD),
width = 0.5,
color = errorbar_color) +
geom_point(data = sel_group_obs,
mapping = aes(x = YEAR, y = BIOMASS_MT),
color = point_color) +
geom_path(data = sel_group_fit,
mapping = aes(x = year, y = pred),
color = timeseries_color,
size = rel(1.1)) +
scale_y_continuous(name = paste0("Biomass Index (", set_unit, ")"),
expand = expansion(mult = c(0, 0.05)),
labels = lab_fun(trim = lab_trim)) +
scale_x_continuous(name = "Year",
breaks = year_breaks,
labels = year_labels) +
expand_limits(y = y_axis_min) +
facet_wrap(~group_name[kk]) +
theme_blue_strip()

}

if(error_bar & benchmarks == "zscore") {

p1 <- ggplot() +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = z_mean),
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = plus1),
linetype = 2,
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = minus1),
linetype = 2,
color = hline_color) +
geom_ribbon(data = sel_group_fit,
mapping = aes(x = year,
ymin = pred_lci,
ymax = pred_uci),
alpha = 0.3,
fill = ribbon_fill) +
geom_errorbar(data = sel_group_obs,
mapping = aes(x = YEAR,
ymin = BIOMASS_PLUS2_SD,
ymax = BIOMASS_MINUS2_SD),
width = 0.5,
color = errorbar_color) +
geom_path(data = sel_group_fit,
mapping = aes(x = year,
y = pred),
color = timeseries_color,
size = rel(1.1)) +
geom_point(data = sel_group_obs,
mapping = aes(x = YEAR, y = BIOMASS_MT),
color = point_color) +
scale_y_continuous(name = paste0("Biomass Index (", set_unit, ")"),
expand = expansion(mult = c(0, 0.05)),
labels = lab_fun(trim = lab_trim)) +
scale_x_continuous(name = "Year",
breaks = year_breaks,
labels = year_labels) +
expand_limits(y = y_axis_min) +
facet_wrap(~group_name) +
theme_blue_strip()

}

if(!error_bar & benchmarks == "zscore") {
p1 <- ggplot() +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = z_mean)) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = plus1),
linetype = 2,
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = minus1),
linetype = 2,
color = hline_color) +
geom_ribbon(data = sel_group_fit,
mapping = aes(x = year,
ymin = pred_lci,
ymax = pred_uci),
alpha = 0.3,
fill = ribbon_fill) +
geom_path(data = sel_group_fit,
mapping = aes(x = year, y = pred),
color = timeseries_color,
size = rel(1.1)) +
geom_point(data = sel_group_obs,
mapping = aes(x = YEAR, y = BIOMASS_MT),
color = point_color) +
scale_y_continuous(name = paste0("Biomass Index (", set_unit, ")"),
expand = expansion(mult = c(0, 0.05)),
labels = lab_fun(trim = lab_trim)) +
scale_x_continuous(name = "Year",
breaks = year_breaks,
labels = year_labels) +
expand_limits(y = y_axis_min) +
facet_wrap(~group_name) +
theme_blue_strip()
}


if(error_bar & benchmarks == "quantile") {

p1 <- ggplot() +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q50)) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q75),
linetype = 2,
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q100),
linetype = 3,
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q25),
linetype = 2,
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q0),
linetype = 3,
color = hline_color) +
geom_ribbon(data = sel_group_fit,
mapping = aes(x = year,
ymin = pred_lci,
ymax = pred_uci),
alpha = 0.3,
fill = ribbon_fill) +
geom_path(data = sel_group_fit,
mapping = aes(x = year, y = pred),
color = timeseries_color,
size = rel(1.1)) +
geom_point(data = sel_group_obs,
mapping = aes(x = YEAR, y = BIOMASS_MT),
color = point_color) +
scale_y_continuous(name = paste0("Biomass Index (", set_unit, ")"),
expand = expansion(mult = c(0, 0.05)),
labels = lab_fun(trim = lab_trim)) +
scale_x_continuous(name = "Year",
breaks = year_breaks,
labels = year_labels) +
expand_limits(y = y_axis_min) +
facet_wrap(~group_name) +
theme_blue_strip()

}

if(!error_bar & benchmarks == "quantile") {
p1 <- ggplot() +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q50)) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q75),
linetype = 2,
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q100),
linetype = 3,
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q25),
linetype = 2,
color = hline_color) +
geom_hline(data = sel_group_ts_summary,
mapping = aes(yintercept = q0),
linetype = 3,
color = hline_color) +
geom_ribbon(data = sel_group_fit,
mapping = aes(x = year,
ymin = pred_lci,
ymax = pred_uci),
alpha = 0.3,
fill = ribbon_fill) +
geom_path(data = sel_group_fit,
mapping = aes(x = year, y = pred),
color = timeseries_color,
size = rel(1.1)) +
geom_point(data = sel_group_obs,
mapping = aes(x = YEAR, y = BIOMASS_MT),
color = point_color) +
scale_y_continuous(name = paste0("Biomass Index (", set_unit, ")"),
expand = expansion(mult = c(0, 0.05)),
labels = lab_fun(trim = lab_trim)) +
scale_x_continuous(name = "Year",
breaks = year_breaks,
labels = year_labels) +
expand_limits(y = y_axis_min) +
facet_wrap(~group_name) +
theme_blue_strip()
}

suppressWarnings(dir.create(paste0("./plots/", region, "/plots_by_group"), recursive = TRUE))

grDevices::png(filename = paste0("./plots/", region, "/", "/plots_by_group/", region, "_rema_",
gsub(x = indicator_name[ii], pattern = " ", replacement = "_"),
"_",
gsub(x = group_name[kk], pattern = " ", replacement = "_"),
"_full_region", append_filename, ".png"),
width = 169,
height = 60,
units = "mm",
res = 300)
print(p1)
grDevices::dev.off()


}

}

return(plot_list)
Expand Down
1 change: 1 addition & 0 deletions man/esrindex-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified plots/AI/AI_rema_forage_fish_full_region_ze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/AI/AI_rema_misc_species_full_region_ze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/AI/AI_rema_structural_epifauna_full_region_ze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/GOA/GOA_rema_forage_fish_full_region_ze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plots/GOA/GOA_rema_misc_species_full_region_ze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8b4c183

Please sign in to comment.