Visualizing Age-Length Keys
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Lately, I have been interested in methods related to age-length keys. One aspect of this interest has been in visualizing age-length keys. I had seen various visualizations in publications and wanted to be able to reproduce those relatively efficiently. To do this, I have created ageKeyPlot()
in the latest version of FSA. Below are examples of the types of visualizations I have coded thusfar. They are not flexible enough yet to be used in publications but I think they may be useful for everyday work. Please let me know what you think and if you have any suggestions for improvements.
Note that the code below requires the the latest version of FSA (version 0.4.6). I am now distributing FSA through GitHub; see these new install instructions.
library(FSA)
Create an Age-Length Key
The code below creates an age-length key from the WR79
data set built into FSA.
data(WR79) # get the age sample from the data frame WR.age <- Subset(WR79, !is.na(age)) # add length categories WR.age.mod <- lencat(~len,data=WR.age,startcat=35,w=5) # create age-length key raw <- table(WR.age.mod$LCat, WR.age.mod$age) WR.key <- prop.table(raw, margin=1) round(WR.key,3) # round() for display only ## ## 4 5 6 7 8 9 10 11 ## 35 1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 ## 40 1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 ## 45 1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 ## 50 1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 ## 55 1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 ## 60 0.600 0.400 0.000 0.000 0.000 0.000 0.000 0.000 ## 65 0.000 1.000 0.000 0.000 0.000 0.000 0.000 0.000 ## 70 0.000 1.000 0.000 0.000 0.000 0.000 0.000 0.000 ## 75 0.000 0.889 0.111 0.000 0.000 0.000 0.000 0.000 ## 80 0.000 0.250 0.750 0.000 0.000 0.000 0.000 0.000 ## 85 0.000 0.000 0.909 0.091 0.000 0.000 0.000 0.000 ## 90 0.000 0.000 0.263 0.632 0.105 0.000 0.000 0.000 ## 95 0.000 0.000 0.059 0.706 0.176 0.000 0.059 0.000 ## 100 0.000 0.000 0.000 0.556 0.167 0.278 0.000 0.000 ## 105 0.000 0.000 0.000 0.286 0.429 0.143 0.143 0.000 ## 110 0.000 0.000 0.000 0.200 0.200 0.200 0.200 0.200 ## 115 0.000 0.000 0.000 0.000 0.000 0.000 1.000 0.000
Barplot
The default plot from ageKeyPlot()
is a barplot where each portion of the bar is the propotion of fish in that length category that are of a given age. This plot is created as follows.
ageKeyPlot(WR.key)
The age labels can be removed and a legend of sorts can be added as follows.
ageKeyPlot(WR.key,showLegend=TRUE)
Stacked Area Plot
A stacked area plot is similar to the barplot. This plot, with a legend, is created with the following.
ageKeyPlot(WR.key,type="area",showLegend=TRUE)
Lines Plot
A plot with lines that connect the proportions of one age across the various length categories is constructed with the following (also demonstrating how to make the default labels larger).
ageKeyPlot(WR.key,type="lines",lbl.cex=1.5)
Splines Plot
A plot with lines that connect the proportions of one age across the various length categories as represented by a smoothing spline is constructed with the following.
ageKeyPlot(WR.key,type="splines",lbl.cex=1.5)
The splines are not “perfect” but they are an attempt to smooth out the lines that connect the proportions. A lower span=
value will reduce the curvature of the splines, which will result in fewer values either greater than 1 or less than 0.
ageKeyPlot(WR.key,type="splines",span=0.2,lbl.cex=1.5)
Comments
Some of the plots do not work with “poorly constructed” age-length keys (e.g., lengths with no age data). I have tried to code “catches” and “work arounds” for these issues but have likely not anticipated all problems. So, let me know how these plots, and this function, work with your age-length keys.
Filed under: Fisheries Science, R Tagged: Age, Age Key, Age-Length Key, R, Visualization
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.