fishR-Core-Team / FSA

FSA (Fisheries Stock Assessment) package provides R functions to conduct typical introductory fisheries analyses.
https://fishr-core-team.github.io/FSA/
GNU General Public License v2.0
65 stars 20 forks source link

Need to free up ylim= in plot.catchCurve() #70

Closed droglenc closed 3 years ago

droglenc commented 3 years ago

The current version of plot.catchCurve() hard-wires the y-axis limits. This should be fixed to allow the user to set the limits. The following change works but it may be better to have ylim=NULL in the function definition, query if it is NULL, and the set the default limits as shown.

plot.catchCurve <- function(x,pos.est="topright",cex.est=0.95,
                            ylab="log(Catch)",xlab="Age",
                            col.pt="gray30",col.mdl="black",lwd=2,lty=1,
                            ylim=c(min(0,min(log(x$catch),na.rm=TRUE)),max(log(x$catch),na.rm=TRUE)),
                            ...) {
  # nocov start
  # Plot raw data
  graphics::plot(log(x$catch)~x$age,col=col.pt,xlab=xlab,ylab=ylab,ylim=ylim,...)
  # Highlight descending limb portion
  graphics::points(x$age.e,x$log.catch.e,col=col.pt,pch=19)
  # Put model on descending limb
  graphics::lines(x$age.e,stats::predict(x$lm,data.frame(x$age.e)),lwd=lwd,lty=lty,col=col.mdl)
  # Put mortality values on the plot
  if (!is.null(pos.est)) {
    Z <- -stats::coef(x$lm)[2]
    A <- 100*(1-exp(-Z))
    graphics::legend(pos.est,legend=paste0("Z=",round(Z,3),"\nA=",round(A,1),"%"),
                     bty="n",cex=cex.est)
  }
} # nocov end

This function was written a long time ago. Probably worth making other edits (e.g., not hard-wiring the rounding values).

Thanks to Brendan Runde ... North Carolina State.

droglenc commented 3 years ago

Fixed in v0.9.0