library(ggplotFL)
library(plyr)
library(reshape)
library(FLBRP)
library(FLife)

Install FLR packages

To follow this tutorial a number of packages need to be installed, either from CRAN or from www.flr-project.org where variety of packages and tutorials are available.

install.packages(c("FLCore","FLFishery","FLasher","FLBRP","mpb","FLife"), 
             repos="http://flr-project.org/R")

devtools also needs to be installed and loaded so that the mydas package can be installed from the GitHub repository.

install.packages("devtools",dependencies=TRUE)
library(devtools)

devtools::install_github("lauriekell/mydas-pkg")

Load Libraries

library(plyr)
library(reshape)
library(ggplot2)
library(FLCore)
library(FLasher)
library(FLBRP)
library(FLife)
library(mydas)

Plotting

Plotting is done using ggplot2 which provides a powerful alternative paradigm for creating both simple and complex plots in R using the ideas the Grammar of Graphics1 The idea of the grammar is to specify the individual building blocks of a plot and then to combine them to create the graphic desired2.

The ggplotFL has default plots for the main FLR objects.

The ggplot functions expects a data.frame for its first argument, data; then a geometric object geom that specifies the actual marks put on to a plot and an aesthetic that is “something you can see” have to be provided. Examples of geometic Objects (geom) include points (geom_point, for scatter plots, dot plots, etc), lines (geom_line, for time series, trend lines, etc) and boxplot (geom_boxplot, for, well, boxplots!). Aesthetic mappings are set with the aes() function and, examples include, position (i.e., on the x and y axes), color (“outside” color), fill (“inside” color), shape (of points), linetype and size.

Life history parameters

Get fishbase data

load(url("https://github.com//fishnets//fishnets//blob//master//data//fishbase-web//fishbase-web.RData?raw=True"))

Select turbot as a case study

lh=subset(fb,species=="Psetta maxima")

names(lh)[c(14,17)] = c("l50","a50")
lh=lh[,c("linf","k","t0","a","b","a50","l50")]

head(lh)
     linf    k    t0      a    b a50  l50
3697 53.9 0.27 -0.12     NA   NA  NA   NA
3698 81.5 0.21 -0.48     NA   NA  NA   NA
3699 54.6 0.31 -0.12 0.0189 2.93   4 49.0
3700 78.6 0.19 -0.80     NA   NA  NA   NA
3701 54.4 0.23 -0.22 0.0219 2.92  NA 37.5
3702 73.6 0.28  0.08 0.0189 2.93   4 49.0

Get the means and create an FLPar object

lh=apply(lh,2,mean,na.rm=T)
lh=FLPar(lh)

Values can be replace with any better estimates that may be available.

lhPar fills in missing values using life history theory, while quantities like selection-at-age are set using defaults, in this case set to be the same as maturity-at-age.

par=lhPar(lh)
par
An object of class "FLPar"
params
     linf         k        t0         a         b     ato95       a50 
  58.6840    0.2868   -0.3120    0.0204    2.9250    1.0000    4.0000 
     asym        bg        a1        sl        sr         s         v 
   1.0000    2.9250    5.0000    1.0000 5000.0000    0.9000 1000.0000 
      l50 
  43.2500 
units:  cm 

The parameters are then used by lhEql to simulate the equilibrium dynamics by combining the spawner/yield per recruit relationships with a stock recruitment relationship, by creating an FLBRP object

eq=lhEql(par)

Figure 1 Vectors of m, selection pattern, maturity and weight-at-age.

plot(eq)

Figure 2 Expected, equilibrium, dynamics and reference points.

To model time series the FLBRP object created by lhEql is coerced to an FLStock object and then projected forward

Simulate a time series that represents a stock that was originally lightly exploited, then effort is increased until the stock is overfished and then fishing pressure was reduced to recover the stock biomass to BMSY.

fbar(eq)=refpts(eq)["msy","harvest"]%*%FLQuant(c(rep(.1,19),
                                              seq(.1,2,length.out = 30)[-30],
                                              seq(2,1.0,length.out = 10),
                                              rep(1.0,61)))[,1:105]
plot(fbar(eq))

Coercing the FLBRP object into an FLStock

om=as(eq,"FLStock")

Call fwd() with the stock, the target F and a stock recruitment relationship

om=fwd(om,fbar=fbar(om)[,-1], sr=eq)

Figure 3 Stochastic Time series of F, SSB, recruitment and yield

plot(FLQuants(om,   
          "ssb" = function(x) ssb(x)%/%refpts( eq)["msy","ssb"], 
          "f" =   function(x) fbar(x)%/%refpts(eq)["msy","harvest"], 
          "rec" = function(x) rec(x)%/%refpts( eq)["msy","rec"], 
          "catch"=function(x) landings(x)%/%refpts(eq)["msy","yield"])) + 
  geom_hline(aes(yintercept=1),col="red") 

Figure 4 Time series relative to MSY benchmarks.

Stochasticity

Add recruitment variability into add the residuals argument, e.g. for 100 Monte Carlo simulations with a CV of 0.3

nits=100

srDev=rlnoise(nits, rec(om) %=% 0, 0.3)

om=propagate(om,nits)

om=fwd(om,fbar=fbar(om)[,-1], sr=eq, residuals=srDev)
plot(om)

Figure 5 Simulate a stock with increasing F

Software Versions

Author information

Laurence KELL. laurie@seaplusplus.co.uk

Acknowledgements

References


  1. Wilkinson, L. 1999. The Grammar of Graphics, Springer. doi 10.1007/978-3-642-21551-3_13.

  2. http://tutorials.iq.harvard.edu/R/Rgraphics/Rgraphics.html