http://rpubs.com/pl202/436164

library(knitr)
## Global options
opts_chunk$set(cache     =TRUE,
               cache.path='cache/performance/',
               echo      =TRUE,
               eval      =TRUE,
               prompt    =FALSE,
               comment   =NA,
               message   =FALSE,
               warning   =FALSE,
               tidy      =FALSE,
               fig.height=6,
               fig.width =8,
               fig.path  ='tex/performance-')


iFig=0
library(ggplotFL)
library(plyr)
library(reshape)
library(FLBRP)
library(FLife)
theme_set(theme_bw())
options(digits=3)

Install FLR packages

To follow this tutorial you will have to install a number of packages, either from CRAN or from www.flr-project.org where variety of packages and tutorials are available.

Install FLR from https://www.flr-project.org/

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

devtools needs to be installed and then loaded so that the mydas package can be installed from this 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)
options(scipen = 999)

library(DBI)
library(RPostgreSQL)
drv  = dbDriver("PostgreSQL")

con  = dbConnect(drv, host = 'postgresql-seascope.csffkpr9jjjn.eu-west-2.rds.amazonaws.com',
                 dbname='FLRout',
                 port = 5432,
                 user = 'MydasApplication',
                 password = 'gmit2017!')
mpb  = dbGetQuery(con1, paste("select* from mpb where spp = 'turbot' and year < 94"))

ss_labels = c("0.7"="Ftar=0.7", "1"="Ftar=1")
ggplot(mpb, aes(as.factor(year), ssb/msy_ssb,fill=as.factor(btrig)))+
      geom_boxplot(outlier.size=0.1, position=position_dodge(1),width=0.8, lwd=0.05, notch=TRUE)+
      stat_summary(fun.y=mean, geom="line", aes(group=1))+
      geom_hline(aes(yintercept=1), size=0.75, colour= "red", linetype="dashed")+ 
      facet_wrap(~ftar,ncol=1, labeller = labeller(ftar = ss_labels),scale="free_y") + theme_bw() +
      theme(panel.grid.major = element_blank(),
      text = element_text(size=14),
      panel.grid.minor = element_blank(),
      strip.background = element_blank(),
      panel.border = element_rect(colour = "black"),
      legend.position="bottom") + 
      scale_colour_manual(values=c("white", "#56B4E9"), labels=c("0.5","0.6"))  + 
      scale_fill_manual(name=expression(B[trig]),values=c("white", "#56B4E9"), labels=c("0.5","0.6")) + 
      scale_x_discrete(breaks = c(50,60,70,80,90))+
      scale_y_continuous(breaks = c(0:5))+
      xlab("year")+ylab(expression(B/B[MSY]))

ggplot(mpb, aes(as.factor(year), catch/msy_yield,fill=as.factor(btrig)))+
      geom_boxplot(outlier.size=0.1, position=position_dodge(1),width=0.8, lwd=0.05, notch=TRUE)+
      stat_summary(fun.y=mean, geom="line", aes(group=1))+
      geom_hline(aes(yintercept=1), size=0.75, colour= "red", linetype="dashed")+ 
      facet_wrap(~ftar,ncol=1, labeller = labeller(ftar = ss_labels),scale="free_y") + theme_bw() +
      theme(panel.grid.major = element_blank(),
      text = element_text(size=14),
      panel.grid.minor = element_blank(),
      strip.background = element_blank(),
      panel.border = element_rect(colour = "black"),
      legend.position="bottom") + 
      scale_colour_manual(values=c("white", "#56B4E9"), labels=c("0.5","0.6"))  + 
      scale_fill_manual(name=expression(B[trig]),values=c("white", "#56B4E9"), labels=c("0.5","0.6")) + 
      scale_x_discrete(breaks = c(50,60,70,80,90))+
      scale_y_continuous(breaks = c(0:5))+
      xlab("year")+ylab(expression(catch/catch[MSY]))

ggplot(mpb,aes(as.factor(year), fbar/msy_harvest,fill=as.factor(btrig)))+
      geom_boxplot(outlier.size=0.1, position=position_dodge(1),width=0.8, lwd=0.05, notch=TRUE)+
      stat_summary(fun.y=mean, geom="line", aes(group=1))+
      geom_hline(aes(yintercept=1), size=0.75, colour= "red", linetype="dashed")+ 
      facet_wrap(~ftar,ncol=1, labeller = labeller(ftar = ss_labels),scale="free_y") + theme_bw() +
      theme(panel.grid.major = element_blank(),
      text = element_text(size=14),
      panel.grid.minor = element_blank(),
      strip.background = element_blank(),
      panel.border = element_rect(colour = "black"),
      legend.position="bottom") + 
      scale_colour_manual(values=c("white", "#56B4E9"), labels=c("0.5","0.6"))  + 
      scale_fill_manual(name=expression(B[trig]),values=c("white", "#56B4E9"), labels=c("0.5","0.6")) + 
      scale_x_discrete(breaks = c(50,60,70,80,90))+
      scale_y_continuous(breaks = c(0:5))+
      xlab("year")+ylab(expression(f/f[MSY]))

Figure r iFig=iFig+1; iFig

Software Versions

Author information

Laurence KELL. laurie@seaplusplus.co.uk

Acknowledgements

References {#References}



laurieKell/mydas-pkg documentation built on Nov. 8, 2019, 10:58 p.m.