R/compareResults.Pop.MatureBiomass.R

Defines functions compareResults.Pop.MatureBiomass

Documented in compareResults.Pop.MatureBiomass

#'
#'@title Function to compare mature biomass-at-mating estimates by year among several models
#'
#'@description This function compares mature biomass-at-mating estimates by year
#'   among several models.
#'
#'@param objs - list of resLst objects
#'@param numRecent - number of "recent" years to plot
#'@param dodge - width to dodge overlapping series
#'@param plotPoints - flag to include points
#'@param colour_scale - ggplot2 colour scale to substitute for default (if not NULL)
#'@param fill_scale - ggplot2 fill scale to substitute for default (if not NULL)
#'@param showPlot - flag (T/F) to show plot
#'@param pdf - creates pdf, if not NULL
#'@param verbose - flag (T/F) to print diagnostic information
#'
#'@return ggplot2 object
#'
#'@details uses \code{rCompTCMs::extractMDFR.Pop.MatureBiomass}, and
#'\code{plotMDFR.XY}.
#'
#'@import ggplot2
#'
#'@export
#'
compareResults.Pop.MatureBiomass<-function(objs,
                                           numRecent=15,
                                           dodge=0.2,
                                           plotPoints=TRUE,
                                           colour_scale=NULL,
                                           fill_scale=NULL,
                                           showPlot=FALSE,
                                           pdf=NULL,
                                           verbose=FALSE){
    if (verbose) cat("Starting rCompTCMs::compareResults.Pop.MatureBiomass().\n");
    options(stringsAsFactors=FALSE);

    cases<-names(objs);

    #create pdf, if necessary
    if(!is.null(pdf)){
        pdf(file=pdf,width=11,height=8,onefile=TRUE);
        on.exit(grDevices::dev.off());
        showPlot<-TRUE;
    }

    mdfr<-extractMDFR.Pop.MatureBiomass(objs,verbose=verbose);

    idx<-mdfr$y>=(max(mdfr$y)-numRecent);

    #----------------------------------
    #mature biomass
    #----------------------------------
    plots<-list();
    p<-plotMDFR.XY(mdfr,x='y',agg.formula=NULL,faceting=NULL,
                   xlab='year',ylab='Mature Biomass',units="1000's t",lnscale=FALSE,
                   facet_grid='x~.',dodge=dodge,
                   plotPoints=plotPoints,
                   colour_scale=colour_scale,
                   fill_scale=fill_scale,
                   colour='case',guideTitleColor='',
                   shape='case',guideTitleShape='');
    if (showPlot||!is.null(pdf)) print(p);
    cap1<-"  \n  \nFigure &&figno. Estimated annual mature biomass.  \n  \n";
    plots[[cap1]]<-p;
    p<-plotMDFR.XY(mdfr[idx,],x='y',agg.formula=NULL,faceting=NULL,
                   xlab='year',ylab='Mature Biomass',units="1000's t",lnscale=FALSE,
                   facet_grid='x~.',dodge=dodge,
                   plotPoints=plotPoints,
                   colour_scale=colour_scale,
                   fill_scale=fill_scale,
                   colour='case',guideTitleColor='',
                   shape='case',guideTitleShape='');
    if (showPlot||!is.null(pdf)) print(p);
    cap1<-"  \n  \nFigure &&figno. Estimated recent mature biomass.  \n  \n";
    plots[[cap1]]<-p;

    p<-plotMDFR.XY(mdfr,x='y',agg.formula=NULL,faceting=NULL,
                   xlab='year',ylab='Mature Biomass',units="1000's t",lnscale=TRUE,
                   facet_grid='x~.',dodge=dodge,
                   plotPoints=plotPoints,
                   colour_scale=colour_scale,
                   fill_scale=fill_scale,
                   colour='case',guideTitleColor='',
                   shape='case',guideTitleShape='');
    if (showPlot||!is.null(pdf)) print(p);
    cap1<-"  \n  \nFigure &&figno. Estimated annual mature biomass, on ln-scale.  \n  \n";
    plots[[cap1]]<-p;
    p<-plotMDFR.XY(mdfr[idx,],x='y',agg.formula=NULL,faceting=NULL,
                   xlab='year',ylab='Mature Biomass',units="1000's t",lnscale=TRUE,
                   facet_grid='x~.',dodge=dodge,
                   plotPoints=plotPoints,
                   colour_scale=colour_scale,
                   fill_scale=fill_scale,
                   colour='case',guideTitleColor='',
                   shape='case',guideTitleShape='');
    if (showPlot||!is.null(pdf)) print(p);
    cap1<-"  \n  \nFigure &&figno. Estimated recent mature biomass, on ln-scale.  \n  \n";
    plots[[cap1]]<-p;

    if (verbose) cat("Finished rCompTCMs::compareResults.Pop.MatureBiomass()!\n");
    return(plots)
}
wStockhausen/rCompTCMs documentation built on Sept. 12, 2023, 3:13 p.m.