Title: | Visualise and Calculate Life History Parameters for Fisheries Science using 'ggplot2' |
---|---|
Description: | Contains functions to create life history parameter plots from raw data. The plots are created using 'ggplot2', and calculations done using the 'tidyverse' collection of packages. The package contains references to FishBase (Froese R., Pauly D., 2023) <https://www.fishbase.se/>. |
Authors: | Mikko Vihtakari [aut, cre] (Institute of Marine Research, <https://orcid.org/0000-0003-0371-4319>) |
Maintainer: | Mikko Vihtakari <[email protected]> |
License: | GPL-3 |
Version: | 0.3.0 |
Built: | 2024-11-12 04:56:54 UTC |
Source: | https://github.com/deepwaterimr/ggfishplots |
Plot a catch curve to estimate instantaneous total mortality (Z) using age data
plot_catchcurve( dt, age = "age", sex = "sex", time = NULL, age.range = NULL, female.sex = "F", male.sex = "M", split.by.sex = FALSE, base_size = 8, legend.position = "bottom" )
plot_catchcurve( dt, age = "age", sex = "sex", time = NULL, age.range = NULL, female.sex = "F", male.sex = "M", split.by.sex = FALSE, base_size = 8, legend.position = "bottom" )
dt |
A data.frame, tibble or data.table |
age |
Character argument giving the name of the age column in |
sex |
Character argument giving the name of the sex column in |
time |
Split analysis by time? If |
age.range |
Defines the age range to be used for Z estimation. If |
female.sex , male.sex
|
A character or integer denoting female and male sex in the |
split.by.sex |
Logical indicating whether the result should be split by sex. |
base_size |
Base size parameter for ggplot. See ggtheme. |
legend.position |
Position of the ggplot legend as a character. See ggtheme. |
Calculates and plots the basic log-linearized catch curve to estimate instantaneous mortality. See e.g. Ogle (2013).
Mikko Vihtakari // Institute of Marine Research.
# Catch curve including all ages data(survey_ghl) plot_catchcurve(survey_ghl) # Specific ages plot_catchcurve(survey_ghl, age.range = c(10,26)) # Split by sex plot_catchcurve(survey_ghl, age.range = c(10,26), split.by.sex = TRUE) # Split by sex, separate age.range plot_catchcurve(survey_ghl, age.range = list("F" = c(13,26), "M" = c(10,26)), split.by.sex = TRUE)
# Catch curve including all ages data(survey_ghl) plot_catchcurve(survey_ghl) # Specific ages plot_catchcurve(survey_ghl, age.range = c(10,26)) # Split by sex plot_catchcurve(survey_ghl, age.range = c(10,26), split.by.sex = TRUE) # Split by sex, separate age.range plot_catchcurve(survey_ghl, age.range = list("F" = c(13,26), "M" = c(10,26)), split.by.sex = TRUE)
Plot age-length relationships and growth curves
plot_growth( dt, length = "length", age = "age", sex = "sex", female.sex = "F", male.sex = "M", length.unit = "cm", split.by.sex = FALSE, growth.model = 1, force.zero.group.length = NA, force.zero.group.strength = 10, force.zero.group.cv = 0, show.Linf = TRUE, boxplot = TRUE, base_size = 8, legend.position = "bottom" )
plot_growth( dt, length = "length", age = "age", sex = "sex", female.sex = "F", male.sex = "M", length.unit = "cm", split.by.sex = FALSE, growth.model = 1, force.zero.group.length = NA, force.zero.group.strength = 10, force.zero.group.cv = 0, show.Linf = TRUE, boxplot = TRUE, base_size = 8, legend.position = "bottom" )
dt |
A data.frame, tibble or data.table |
length |
Character argument giving the name of the length column in |
age |
Character argument giving the name of the age column in |
sex |
Character argument giving the name of the sex column in |
female.sex , male.sex
|
A character or integer denoting female and male sex in the |
length.unit |
A character argument giving the unit of |
split.by.sex |
Logical indicating whether the result should be split by sex. |
growth.model |
Integer defining the growth model. 1 = von Bertalanffy, 2 = Gompertz, 3 = Logistic. |
force.zero.group.length |
Numeric indicating the length to which 0-group should be forced. Use |
force.zero.group.strength |
Numeric indicating how many percent of total fish should be added to the specified |
force.zero.group.cv |
Numeric indicating the coefficient of variation for the forced 0-group length. Resulting lengths will be randomly generated from a normal distribution. |
show.Linf |
Logical indicating whether Linf values should be shown as dashed vertical lines. |
boxplot |
Logical indicating whether boxplots ( |
base_size |
Base size parameter for ggplot. See ggtheme. |
legend.position |
Position of the ggplot legend as a character. See ggtheme. |
Uses the fishmethods::growth
function to calculate the growth curves. Zero group length can be forced to the growth functions using the force.zero.group.*
parameters.
A list containing the plot
, text
for Rmarkdown and Shiny applications, and estimated parameters (params
).
Mikko Vihtakari // Institute of Marine Research.
# Simple plot. Note that a list is returned. data(survey_ghl) plot_growth(survey_ghl, length = "length", age = "age") # Split by sex plot_growth(survey_ghl, split.by.sex = TRUE)$plot # Data as points. Forcing zero group to 10 cm plot_growth(survey_ghl, force.zero.group.length = 10, boxplot = FALSE)$plot
# Simple plot. Note that a list is returned. data(survey_ghl) plot_growth(survey_ghl, length = "length", age = "age") # Split by sex plot_growth(survey_ghl, split.by.sex = TRUE)$plot # Data as points. Forcing zero group to 10 cm plot_growth(survey_ghl, force.zero.group.length = 10, boxplot = FALSE)$plot
Plots length-weight relationship for a species and calculates the a and b coefficients used in length-weight conversions.
plot_lw( dt, length = "length", weight = "weight", sex = "sex", female.sex = "F", male.sex = "M", length.unit = "cm", weight.unit = "kg", split.by.sex = FALSE, xlab = "Total length", ylab = "Weight", use.nls = FALSE, init.a = NULL, init.b = NULL, log.axes = FALSE, outlier.percentile = NULL, annotate.coefficients = FALSE, correct.units = FALSE, base_size = 8, legend.position = "bottom", point.size = 0.5, verbose = TRUE )
plot_lw( dt, length = "length", weight = "weight", sex = "sex", female.sex = "F", male.sex = "M", length.unit = "cm", weight.unit = "kg", split.by.sex = FALSE, xlab = "Total length", ylab = "Weight", use.nls = FALSE, init.a = NULL, init.b = NULL, log.axes = FALSE, outlier.percentile = NULL, annotate.coefficients = FALSE, correct.units = FALSE, base_size = 8, legend.position = "bottom", point.size = 0.5, verbose = TRUE )
dt |
A data.frame, tibble or data.table |
length |
Character argument giving the name of the length column in |
weight |
Character argument giving the name of the age column in |
sex |
Character argument giving the name of the sex column in |
female.sex , male.sex
|
A character or integer denoting female and male sex in the |
length.unit |
Character argument giving the unit of |
weight.unit |
Character argument giving the unit of |
split.by.sex |
Logical indicating whether the result should be split by sex. |
xlab |
Character giving the x-axis label without unit |
ylab |
Character giving the x-axis label without unit. |
use.nls |
Logical indicating whether the parameters should be estimated using the nonlinear least squares ( |
init.a , init.b
|
Numeric values giving the starting value for a and b coefficients respectively for non-linear least-squares estimation (i.e. when |
log.axes |
Logical indicating whether logarithmic axes should be used instead of Cartesian ones. |
outlier.percentile |
Numeric argument giving the probability as a percent value which should be used to calculate residual quantiles for outlier removal. See details. Values > 99 are recommended. If |
annotate.coefficients |
Logical indicating whether the a and b coefficients should be annotated into the plot. |
correct.units |
Logical indicating whether the a and b coefficients should be converted for centimeters and grams as in FishBase. |
base_size |
Base size parameter for ggplot. See ggtheme. |
legend.position |
Position of the ggplot legend as a character. See ggtheme. |
point.size |
Numeric defining the size for data points in the plot. See the |
verbose |
Logical indicating whether to return warnings and messages. |
The function estimates the a and b coefficients of the length weight relationship, , and plots the data. The model can be fitted either using the standard log(weight) ~ log(length) regression (lm; default) or nonlinear least squares (nls) method. The nls method often manages to fit steeper slopes making the b parameter higher and the a parameter lower than the linear lm method. This tends to lead to visually more pleasing fits at high lengths and weights.
The a and b coefficients are dependent on the units of length and weight. In models, the length and weight units should often match those of the data going into the model, while in comparisons with FishBase, the units of length and weight should be centimeters and grams, respectively. If the units are wrong, the intercept, a, will be off the FishBase scale by orders of magnitude (see FishBase). The correct.units
can be used to correct the data units to the FishBase standard (cm and g). The function also returns a warning when the returned parameters are not within expected bounds for cm and g estimation. It is recommended to compare the a and b coefficients with those in FishBase for the species as a quality assurance.
The outlier.percentile
argument enables quick removal of troublesome outliers from the model estimation. The argument is defined as percentile probabilities and used to calculate quantile for absolute residual values from logarithmic regression to identify outliers (). These outliers are then removed from model dataset but plotted using crosses in the ggplot output. See Examples.
A list with three elements: a ggplot object containing the plot, text giving the central statistics that can be pasted to Markdown, and the model parameters (params).
Mikko Vihtakari // Institute of Marine Research.
data(survey_ghl) # Simple plot plot_lw(survey_ghl, length = "length", weight = "weight") # nls plot_lw(survey_ghl, use.nls = TRUE) # Split by sex, annotate coefficients plot_lw(survey_ghl, split.by.sex = TRUE, annotate.coefficients = TRUE)$plot # Outlier removal plot_lw(survey_ghl, outlier.percentile = 99)
data(survey_ghl) # Simple plot plot_lw(survey_ghl, length = "length", weight = "weight") # nls plot_lw(survey_ghl, use.nls = TRUE) # Split by sex, annotate coefficients plot_lw(survey_ghl, split.by.sex = TRUE, annotate.coefficients = TRUE)$plot # Outlier removal plot_lw(survey_ghl, outlier.percentile = 99)
Plots an estimate of length or age at 50% mature for a dataset
plot_maturity( dt, length = "length", maturity = "maturity", sex = "sex", split.by.sex = FALSE, female.sex = "F", male.sex = "M", length.unit = "cm", length.bin.width = 2, bootstrap.n = NA, force.zero.group.length = NA, force.zero.group.strength = NA, force.zero.group.n = NA, force.zero.group.cv = 0, xlab = "Total length", base_size = 8, legend.position = "bottom", ... )
plot_maturity( dt, length = "length", maturity = "maturity", sex = "sex", split.by.sex = FALSE, female.sex = "F", male.sex = "M", length.unit = "cm", length.bin.width = 2, bootstrap.n = NA, force.zero.group.length = NA, force.zero.group.strength = NA, force.zero.group.n = NA, force.zero.group.cv = 0, xlab = "Total length", base_size = 8, legend.position = "bottom", ... )
dt |
A data.frame, tibble or data.table |
length |
Character argument giving the name of the length (or age) column in |
maturity |
Character argument giving the name of the maturity column in |
sex |
Character argument giving the name of the sex column in |
split.by.sex |
Logical indicating whether the result should be split by sex. |
female.sex , male.sex
|
A character or integer denoting female and male sex in the |
length.unit |
A character argument giving the unit of |
length.bin.width |
Numeric specifying the increment (delta length) by which length data should be binned to calculate maturity proportions. Use |
bootstrap.n |
Integer defining the number of bootstrap replicates to be used to calculate 95% confidence intervals for the mean 50% mature estimate. If |
force.zero.group.length |
Numeric indicating the length to which 0-group (all immatures) should be forced. Use |
force.zero.group.strength |
Numeric indicating how many percent of total fish should be added to the specified |
force.zero.group.n |
Numeric indicating how many observations should be added to the specified |
force.zero.group.cv |
Numeric indicating the coefficient of variation for the forced 0-group (all immature) length. Resulting lengths will be randomly generated from a normal distribution. |
xlab |
Character giving the x-axis label without unit |
base_size |
Base size parameter for ggplot. See ggtheme. |
legend.position |
Position of the ggplot legend as a character. See ggtheme. |
... |
Additional arguments passed to geom_density_ridges. |
The 95% confidence intervals for the mean 50% mature estimate are calculated using the glm function by default. This routine might not be optimal when zero group fish are added. Hence, the function contains an option to bootstrap confidence intervals using the same number of data than observations (i.e. excluding the added data from the number of randomly resampled rows). Adding an integer to the bootstrap.n
argument turns on this feature. Note that the confidence intervals calculated this way tend to be narrower than the glm()
confidence intervals.
Returns a ggplot2 or tibble depending on the plot
argument showing the maturity ogives.
Mikko Vihtakari // Institute of Marine Research.
# Simple L50 plot data(survey_ghl) plot_maturity(survey_ghl, length = "length", maturity = "maturity") # Bootstrapped CIs are narrower than the glm ones plot_maturity(survey_ghl, bootstrap.n = 10) # A50 plot, split by sex plot_maturity(survey_ghl, length = "age", length.unit = "years", xlab = "Age", length.bin.width = 1, split.by.sex = TRUE)$plot # Add juveniles plot_maturity(survey_ghl, length = "age", length.unit = "years", xlab = "Age", length.bin.width = 1, split.by.sex = TRUE, force.zero.group.length = 0, force.zero.group.strength = 100)$plot
# Simple L50 plot data(survey_ghl) plot_maturity(survey_ghl, length = "length", maturity = "maturity") # Bootstrapped CIs are narrower than the glm ones plot_maturity(survey_ghl, bootstrap.n = 10) # A50 plot, split by sex plot_maturity(survey_ghl, length = "age", length.unit = "years", xlab = "Age", length.bin.width = 1, split.by.sex = TRUE)$plot # Add juveniles plot_maturity(survey_ghl, length = "age", length.unit = "years", xlab = "Age", length.bin.width = 1, split.by.sex = TRUE, force.zero.group.length = 0, force.zero.group.strength = 100)$plot
Greenland halibut measurements from IMR surveys
data(survey_ghl)
data(survey_ghl)
A dataframe
Contains length, weight, age, sex and maturity measurements of Greenland halibut acquired on various surveys.
Institute of Marine Research (https://www.hi.no/hi)
A ggplot2 theme for the ggFishPlots package
theme_fishplots(..., grid.col, grid.size)
theme_fishplots(..., grid.col, grid.size)
... |
additional arguments passed to |
grid.col |
Character code specifying the color of grid lines. Use |
grid.size |
Numeric value specifying the width of grid lines. |
A ggplot2 theme layer.