R/Footprint.R

Defines functions Footprint

Documented in Footprint

# Annual fishery footprint and landings.
#' @title Plot the annual landings, footprint (m2), and associated limits and trigger levels annually.
#' @description Function to subset loci and populations
#' @param CatchData is average catch per year. Columns are ordered as "Year" "se" "sd" and "CPUE". CPUE is the mean CPUE in a givne year.
#' NOte the required input can be generated by the CatchTable function
#' @param SelBank a numeric delimiter of the assessment region (1 = Banquereau and 2 = Grand Bank).
#' @rdname Footprint
#' @import ggplot2
#' @importFrom reshape2 melt
#' @export

Footprint <- function(CatchData, SelBank){

  colnames(CatchData)[c(2:3,5)] <- c("Catch", "Footprint","Area")
  Labs <- c("Catch  (t)", expression(paste("Footprint (",km^2,")",sep=""))) # labels for the plots
  CatchData <- reshape2::melt(CatchData,id.vars=c("Year","Area","CPUE"))

  #Banquereau
  if(SelBank==1){

    limits <- data.frame(x1=c(min(CatchData$Year,na.rm=T),1995,min(CatchData$Year,na.rm=T)),
                         x2=c(1995,max(CatchData$Year,na.rm=T),max(CatchData$Year,na.rm=T)),
                         y1=c(30000,24000,253),y2=c(30000,24000,253))

    #Set up the variables for facetting
    limits$Var=gl(2,2,length=3,labels=Labs) #three points
    CatchData$Var=gl(2,nrow(CatchData)/2,labels=Labs) #Labels with factor levels

  }

  #Grand Bank
  if(SelBank==2){

    limits <- data.frame(x1=c(min(CatchData$Year,na.rm=T),2010,min(CatchData$Year,na.rm=T)),
                         x2=c(2010,max(CatchData$Year,na.rm=T),max(CatchData$Year,na.rm=T)),
                         y1=c(20000,14756,128),y2=c(20000,14756,128))

    #Set up the variables for facetting
    limits$Var=gl(2,2,length=3,labels=Labs) #three points
    CatchData$Var=gl(2,nrow(CatchData)/2,labels=Labs) #Labels with factor levels

  }

  return(ggplot2::ggplot()+
          geom_point(data=CatchData,aes(x=Year,y=value))+
          geom_line(data=CatchData,aes(x=Year,y=value))+
          #geom_line(aes(x=Year,y=limits))+
          geom_segment(data=limits,aes(x=x1,y=y1,xend=x2,yend=y2),lty=2)+
          facet_grid(Var~.,scales="free",labeller = "label_parsed")+
          theme_bw()+
          scale_x_continuous(breaks=seq(min(CatchData$Year,na.rm=T),max(CatchData$Year,na.rm=T),2))+
          labs(x="",y="")+
          theme(strip.background = element_rect(colour = "black", fill = "white"),
                panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
                axis.text.x=element_text(angle = 45,hjust=1)))

} #end function
SurfClam/bio.surfclam documentation built on June 11, 2020, 4:24 p.m.