View source: R/plot-statevar.R
| plot_tradeoff | R Documentation |
Generates a tradeoff figure, a comparison between two performance metrics, across two variables which may represent a population dynamics variable (e.g., productivity) or a management action (e.g., hatchery production levels or harvest strategy). See example at https://docs.salmonmse.com/articles/decision-table.html
plot_tradeoff(
pm1,
pm2,
x1,
x2,
xlab,
ylab,
x1lab,
x2lab,
scenario,
scenario_rows,
scenario_cols,
ncol = NULL,
dir = "v",
add_letters = FALSE
)
pm1 |
Numeric or matrix. A vector of values for the first performance metric on the x-axis. Alternatively, provide a three column matrix corresponding to the lower bound, central tendency, and upper bound. |
pm2 |
Numeric or matrix. A vector of values for the second performance metric on the y-axis (same length as pm1). Alternatively, provide a three column matrix corresponding to the lower bound, central tendency, and upper bound. |
x1 |
Atomic, vector of values for the first grouping variable. Various levels are represented by colours. Same length as pm1. If numeric, you may want to convert values to factors. |
x2 |
Atomic, vector of values for the second grouping variable. Various levels are represented by shapes. Same length as pm1. If numeric, will be converted to factors. |
xlab |
Character, optional x-axis label |
ylab |
Character, optional y-axis label |
x1lab |
Character, optional label for the first grouping variable |
x2lab |
Character, optional label for the second grouping variable |
scenario |
Atomic, vector of scenario names (same length as |
scenario_rows |
Atomic, vector of scenario variables (same length as |
scenario_cols |
Atomic, vector of scenario variables (same length as |
ncol |
Integer, number of columns in the grid, only used if |
dir |
Character, either "h" or "v" to describe how the grid of tables should be organized (horizontally or vertically) , only used if |
add_letters |
Logical, whether to identify separate panels by letters (only used if scenarios are identified). Helpful for publication-level figures |
ggplot object
plot_statevar_ts() plot_decision_table()
# Single tradeoff panel
results <- data.frame(
PNI = c(0.7, 0.23, 0.05, 0.9, 0.85, 0.74, 0.95, 0.92, 0.9),
Catch = c(10, 14, 12, 8, 7, 7, 8.2, 7.1, 6.9),
pNOB = rep(c(0.5, 0.75, 1), each = 3),
ER = rep(c(0.2, 0.3, 0.4), 3),
scenario = "High productivity"
)
plot_tradeoff(
pm1 = results$PNI,
pm2 = results$Catch,
x1 = results$ER,
x2 = results$pNOB,
xlab = "PNI",
ylab = "Catch",
x1lab = "Exploitation\nrate",
x2lab = "pNOB\ntarget"
)
# Multiple panels, continuing from above code
results_low <- results
results_low$scenario <- "Low productivity"
results_low$PNI <- 0.5 * results$PNI
results_low$Catch <- c(0.9, 0.8, 0.7) * results$Catch
results_all <- rbind(results, results_low)
g <- plot_tradeoff(
pm1 = results_all$PNI,
pm2 = results_all$Catch,
x1 = results_all$ER,
x2 = results_all$pNOB,
xlab = "PNI",
ylab = "Catch",
x1lab = "Exploitation\nrate",
x2lab = "pNOB\ntarget",
scenario = results_all$scenario
)
# Change legend with ggplot2
library(ggplot2)
g + scale_shape_manual(values = c(1, 4, 16))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.