#'
#'@title Compare estimated/predicted fishery retention functions among several model runs
#'
#'@description Function to compare estimated/predicted fishery retention functions among
#'several model runs.
#'
#'@param obj - object that can be converted into a list of tcsam2013.resLst objects
#'@param showPlot - flag (T/F) to show plot
#'@param pdf - name for output pdf file
#'
#'@details Uses \code{getMDFR.FisheryQuantities}.
#'
#'@importFrom wtsUtilities printGGList
#'
#'@return list of ggplot2 objects
#'
#'@importFrom wtsUtilities printGGList
#'@import ggplot2
#'
#'@export
#'
compareModelResults.FisheryRetFcns<-function(obj,
showPlot=FALSE,
pdf=NULL){
#create pdf, if necessary
if(!is.null(pdf)){
pdf(file=pdf,width=11,height=8,onefile=TRUE);
on.exit(dev.off());
showPlot<-TRUE;
}
plots<-list();#output list
#----------------------------------
# convert to list of ResLst objects
#----------------------------------
obj<-convertToListOfResults(obj);
#----------------------------------
# pull out generic info
#----------------------------------
cases<-names(obj);
tinfo<-getTimeInfo(obj);
endyr<-tinfo$endyr;
#----------------------------------
# define output list of plots
#----------------------------------
plots<-list();
figno<-1;
#----------------------------------
# plot retention functions
#----------------------------------
dfrp<-getMDFR.FisheryQuantities(obj,'selfcns');
dfrp$case<-factor(dfrp$case,levels=cases);
dfrp$pc<-as.character(dfrp$pc);
idc<-(dfrp$category=="retention");
for (fsh in c('TCF')){
idx<-(dfrp$fleet==fsh);
idt<-(dfrp$pc %in% c('1990', '1991'))
dfrpp<-dfrp[idx&idc&idt,];
p <- ggplot(data=dfrpp,mapping=aes_string(x='z',y='val',colour="case",shape="pc",linetype="pc"));
p <- p + geom_line();
p <- p + geom_point();
p <- p + labs(y="retention",x="size (mm CW)");
p <- p + guides(colour=guide_legend("case"),
shape=guide_legend("time period"),
linetype=guide_legend("time period"));
p <- p + facet_grid(x~fleet);
cap<-paste0(" \n \nFigure &&fno. Estimated retention functions for total catch in",fsh,". \n \n");
if (showPlot) figno<-(printGGList(p,figno=figno,cap=cap))$figno;
plots[[cap]]<-p; p<-NULL;
}
return(invisible(plots));
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.