#===== The string (first) and expression (second) for default type="von Bertalanffy")
showGrowthFun()
showGrowthFun(parse=TRUE)
showGrowthFun(pname="Typical")
#===== Show on a plot, and then larger
showGrowthFun(plot=TRUE)
showGrowthFun(plot=TRUE,cex=2)
#===== Other growth functions
showGrowthFun(type="Richards",param=3,plot=TRUE,cex=1.5)
showGrowthFun(type="Schnute",case=2,plot=TRUE,cex=1.5)
#===== Growth functions which use "where" to define simplifying constants/functions
showGrowthFun(pname="Somers",plot=TRUE)
showGrowthFun(pname="Somers",stackWhere=TRUE,plot=TRUE,cex=1.25)
#===== Multiple expressions in one plot (need to use parse=TRUE here)
op <- par(mar=c(0.1,0.1,0.1,0.1))
plot(0,type="n",xlab="",ylab="",xlim=c(0,1),ylim=c(0,3),xaxt="n",yaxt="n")
text(0,2.5,"Original:",pos=4)
text(0.5,2.5,showGrowthFun(type="von Bertalanffy",pname="Original",parse=TRUE))
text(0,1.5,"Typical:",pos=4)
text(0.5,1.5,showGrowthFun(type="von Bertalanffy",pname="Typical",parse=TRUE))
text(0,0.5,"Francis:",pos=4)
text(0.5,0.5,showGrowthFun(type="von Bertalanffy",pname="Francis",parse=TRUE))
par(op)
#===== Put expression in title or otherwise on the plot
# Make a von Bertalanffy function
vb1 <- makeGrowthFun()
# Get and save the expression of the von Bertalanffy growth function
tmp <- showGrowthFun(parse=TRUE)
# Make plot and put expression in plot title
ages <- 1:20
plot(vb1(ages,Linf=20,K=0.3,t0=-0.2)~ages,type="b",pch=19,ylab="Length",main=tmp)
# Put expression in plot body (as demo)
text(15,10,tmp)
#===== Fill expression with values from model fit
# Fit von Bertalanffy to GrowthData1 data
sv <- findGrowthStarts(tlV~age,data=GrowthData1)
rv <- nls(tlV~vb1(age,Linf,K,t0),data=GrowthData1,start=sv)
# Show expression with values
showGrowthFun(fit=rv,plot=TRUE)
# Same, but control decimals (Linf, K, and then t0 order as in vb1())
showGrowthFun(fit=rv,digits=c(1,5,3),plot=TRUE)
# Same, but change variables
showGrowthFun(fit=rv,yvar="Length",xvar="Age",plot=TRUE)
# Put on a plot
plot(tlV~age,data=GrowthData1,ylab="Length (mm)",xlab="Age (yrs)")
curve(vb1(x,Linf=coef(rv)),from=0,to=15,col="blue",lwd=2,add=TRUE)
text(10,150,showGrowthFun(fit=rv,parse=TRUE))
# Put on a ggplot (note parse=TRUE is outside showGrowthFun)
if (FALSE) {
library(ggplot2)
ggplot(data=GrowthData1,mapping=aes(y=tlV,x=age)) +
geom_point() +
stat_function(fun=vb1,args=list(Linf=coef(rv)),color="blue",linewidth=1) +
annotate(geom="text",label=showGrowthFun(fit=rv),parse=TRUE,size=4,x=10,y=150) +
labs(y="Length (mm)",x="Age (yrs)") +
theme_bw()
}
Run the code above in your browser using DataLab