Skip to content

Commit 4a806f0

Browse files
committed
add labels with specific bycatch levels to figure legend for plot_proj() #54 #57
1 parent eefcdde commit 4a806f0

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

R/00_setup.R

+12
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,15 @@ central <- FALSE
243243
colorscheme <- c("#7bbcb0", "#3a7c89", "#123f5a")
244244
i18n$set_translation_language("en")
245245

246+
247+
# Aesthetics functions ----------------------------------------------------
248+
249+
get_bycatch_legend <- function(x) {
250+
if (all(!is.na(x$ConstantBycatch))) {
251+
a <- paste(c("N", "CV"),"=", x$ConstantBycatch)
252+
} else {
253+
a <- paste(c("Rate", "CV"), "=", x$ConstantRateBycatch)
254+
}
255+
numslabel <- paste0(a[1], " (", a[2], ")")
256+
return(numslabel)
257+
}

R/17_plot_proj.R

+8-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ plot_proj <- function(high,
7979
high.col <- color.palette[3]
8080
med.col <- color.palette[2]
8181
low.col <- color.palette[1]
82-
82+
8383
plottitle <- switch(lang,
8484
"en" = "Model projections",
8585
"es" = "Proyecciones",
@@ -134,7 +134,7 @@ plot_proj <- function(high,
134134
"fr" = "Abondance (N/K)"
135135
)
136136

137-
# setup medians etc
137+
# get quantiles
138138
probs <- c(0.05, 0.25, 0.5, 0.75, 0.95)
139139

140140
# low med and high refer to low med and high bycatch
@@ -157,6 +157,9 @@ plot_proj <- function(high,
157157
med = sdf_labs_med,
158158
low = sdf_labs_low
159159
))
160+
161+
# Get bycatch level labels
162+
blvls <- sapply(X = list(high,med,low),FUN = get_bycatch_legend)
160163

161164
if (spaghetti) {
162165
all$sim <- 1
@@ -186,7 +189,7 @@ plot_proj <- function(high,
186189
p <- sdf %>%
187190
ggplot(aes(x = year, y = value, group = sim, colour = name)) +
188191
geom_path(alpha = 0.2, lwd = 1) +
189-
scale_colour_manual(bylvl_lab, values = rev(color.palette)) +
192+
scale_colour_manual(bylvl_lab, values = rev(color.palette), labels = blvls) +
190193
geom_line(
191194
data = all,
192195
aes(x = year, y = median / K1plus, colour = blvl, group = blvl),
@@ -221,8 +224,8 @@ plot_proj <- function(high,
221224
geom_ribbon(aes(ymin = lo50 / K1plus, ymax = hi50 / K1plus, fill = blvl), alpha = 0.5) +
222225
geom_line(aes(y = median / K1plus, colour = blvl), lwd = 1.1) +
223226
ylim(0, 1) +
224-
scale_fill_manual(bylvl_lab, values = rev(color.palette)) +
225-
scale_colour_manual(bylvl_lab, values = rev(color.palette)) +
227+
scale_fill_manual(bylvl_lab, values = rev(color.palette),labels = blvls) +
228+
scale_colour_manual(bylvl_lab, values = rev(color.palette),labels = blvls) +
226229
xlab(year_lab) +
227230
ylab(abund_lab) +
228231
labs(

0 commit comments

Comments
 (0)