Last data update: 2014.03.03

R: Plots to visualize age-length keys.
alkPlotR Documentation

Plots to visualize age-length keys.

Description

Various plots to visualize the proportion of fish of certain ages within length intervals in an age-length key.

Usage

alkPlot(key, type = c("barplot", "area", "lines", "splines", "bubble"),
  xlab = "Length", ylab = ifelse(type != "bubble", "Proportion", "Age"),
  xlim = NULL, ylim = NULL, showLegend = FALSE, lbl.cex = 1.25,
  leg.cex = 1, lwd = 2, span = 0.25, pal = paletteChoices(),
  grid = TRUE, col = "gray80", buf = 0.45, add = FALSE, ...)

Arguments

key

A numeric matrix that contains the age-length key.

type

A string that indicates the type of plot to construct. See details.

xlab, ylab

A string that contains the label for the x- or y-axis.

xlim, ylim

A numeric of length 2 that provide the limits for the x-axis or y-axis.

showLegend

A logical that indicates whether a legend should be displayed (not implemented for type="bubble"). See examples.

lbl.cex

A numeric character expansion value for labels inside the bars when type="barplot" or on the lines when type="lines" or type="splines". Only used if showLegend=FALSE.

leg.cex

A numeric character expansion value for labels on the legend when showLegend=TRUE.

lwd

A numeric that indicates the line width when type="lines" or type="splines".

span

A numeric that indicates the span value to use in loess when type="splines".

pal

A string that indicates the palette to generate colors for the bars, areas, lines, or spline lines. The name of a palette must be one of “rich”, “cm”, “default”, “grey”, “gray”, “heat”, “jet”, “rainbow”, “topo”, or “terrain”. See chooseColors.

grid

A logical that indicates whether a grid should be placed under the bubbles when type="bubble" or a character or appropriate vector that identifies a color for the grid. See examples.

col

A string that indicates the color of the bubbles when type="bubble".

buf

A single numeric that indicates the relative width of the bubbles when type="bubble". A value of 0.5 means that two full-width bubbles would touch each other either in the x- or y-direction (i.e., this would represent half of the minimum of the physical distance between values one-unit apart on the x- and y-axes). Set this to a value less than 0.5 so that the bubbles will not touch (the default is 0.45).

add

A logical that indicates whether the data should be added to an already existing plot. May be useful for visually comparing age-length keys. Only implemented when type="bubble".

...

Additional arguments to pass to plot or barplot.

Details

A variety of plots can be used to visualize the proportion of fish of certain ages within length intervals of an age-length key. The types of plots are described below and illustrated in the examples.

  • A “stacked” bar chart where vertical bars over length intervals sum to 1 but are segmented by the proportion of each age in that length interval is constructed with type="barplot". The ages will be labeled in the bar segments unless showLegend=TRUE is used.

  • A “stacked” area chart similar to the bar chart described above is constructed with type="area".

  • A plot with (differently colored) lines that connect the proportions of ages within each length interval is constructed with type="lines".

  • A plot with (differently colored) lines, as estimated by loess splines, that connect the proportions of ages within each length interval is constructed with type="splines".

  • A “bubble” plot where circles whose size is proportional to the proportion of fish of each age in each length interval is constructed with type="bubble". The color of the bubbles can be controlled with col= and an underlying grid for ease of seeing the age and length interval for each bubble can be controlled with grid=. Bubbles from a second age-length key can be overlaid on an already constructed bubble plot by using add=TRUE in a second call to alkPlot.

Note that all plots are “vertically conditional” – i.e., each represents the proportional ages WITHIN each length interval.

Value

None, but a plot is constructed.

IFAR Chapter

5-Age-Length Key.

Author(s)

Derek H. Ogle, derek@derekogle.com

References

Ogle, D.H. 2016. Introductory Fisheries Analyses with R. Chapman & Hall/CRC, Boca Raton, FL.

See Also

See alkIndivAge for using an age-length key to assign ages to individual fish.

Examples

## Make an example age-length key
data(WR79)
WR.age <- subset(WR79, !is.na(age))      # isolate the age sample
WR.age$LCat <- lencat(WR.age$len,w=5)    # add length intervals (width=5)
raw <- xtabs(~LCat+age,data=WR.age)      # create age-length key
( WR.key <- prop.table(raw, margin=1) )

## Various visualizations of the age-length key
alkPlot(WR.key,"barplot")
alkPlot(WR.key,"barplot",pal="gray")
alkPlot(WR.key,"barplot",showLegend=TRUE)
alkPlot(WR.key,"area")
alkPlot(WR.key,"area",showLegend=TRUE)
alkPlot(WR.key,"area",pal="gray")
alkPlot(WR.key,"lines")
alkPlot(WR.key,"lines",pal="gray")
alkPlot(WR.key,"lines",showLegend=TRUE)
alkPlot(WR.key,"splines")
alkPlot(WR.key,"splines",span=0.2)
alkPlot(WR.key,"splines",pal="gray",showLegend=TRUE)
alkPlot(WR.key,"bubble")
alkPlot(WR.key,"bubble",grid=FALSE)
alkPlot(WR.key,"bubble",grid="blue")
alkPlot(WR.key,"bubble",grid=rgb(0,0,0,0.2),col=rgb(0,0,0,0.5))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(FSA)


 ############################################
 ##      FSA package, version 0.8.7        ##
 ##    Derek H. Ogle, Northland College    ##
 ##                                        ##
 ## Run ?FSA for documentation.            ##
 ## Run citation('FSA') for citation ...   ##
 ##   please cite if used in publication.  ##
 ##                                        ##
 ## See derekogle.com/fishR/ for more      ##
 ##   thorough analytical vignettes.       ##
 ############################################


> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/FSA/alkPlot.Rd_%03d_medium.png", width=480, height=480)
> ### Name: alkPlot
> ### Title: Plots to visualize age-length keys.
> ### Aliases: alkPlot
> ### Keywords: plot
> 
> ### ** Examples
> 
> ## Make an example age-length key
> data(WR79)
> WR.age <- subset(WR79, !is.na(age))      # isolate the age sample
> WR.age$LCat <- lencat(WR.age$len,w=5)    # add length intervals (width=5)
> raw <- xtabs(~LCat+age,data=WR.age)      # create age-length key
> ( WR.key <- prop.table(raw, margin=1) )
     age
LCat           4          5          6          7          8          9
  35  1.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
  40  1.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
  45  1.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
  50  1.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
  55  1.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
  60  0.60000000 0.40000000 0.00000000 0.00000000 0.00000000 0.00000000
  65  0.00000000 1.00000000 0.00000000 0.00000000 0.00000000 0.00000000
  70  0.00000000 1.00000000 0.00000000 0.00000000 0.00000000 0.00000000
  75  0.00000000 0.88888889 0.11111111 0.00000000 0.00000000 0.00000000
  80  0.00000000 0.25000000 0.75000000 0.00000000 0.00000000 0.00000000
  85  0.00000000 0.00000000 0.90909091 0.09090909 0.00000000 0.00000000
  90  0.00000000 0.00000000 0.26315789 0.63157895 0.10526316 0.00000000
  95  0.00000000 0.00000000 0.05882353 0.70588235 0.17647059 0.00000000
  100 0.00000000 0.00000000 0.00000000 0.55555556 0.16666667 0.27777778
  105 0.00000000 0.00000000 0.00000000 0.28571429 0.42857143 0.14285714
  110 0.00000000 0.00000000 0.00000000 0.20000000 0.20000000 0.20000000
  115 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
     age
LCat          10         11
  35  0.00000000 0.00000000
  40  0.00000000 0.00000000
  45  0.00000000 0.00000000
  50  0.00000000 0.00000000
  55  0.00000000 0.00000000
  60  0.00000000 0.00000000
  65  0.00000000 0.00000000
  70  0.00000000 0.00000000
  75  0.00000000 0.00000000
  80  0.00000000 0.00000000
  85  0.00000000 0.00000000
  90  0.00000000 0.00000000
  95  0.05882353 0.00000000
  100 0.00000000 0.00000000
  105 0.14285714 0.00000000
  110 0.20000000 0.20000000
  115 1.00000000 0.00000000
> 
> ## Various visualizations of the age-length key
> alkPlot(WR.key,"barplot")
> alkPlot(WR.key,"barplot",pal="gray")
> alkPlot(WR.key,"barplot",showLegend=TRUE)
> alkPlot(WR.key,"area")
> alkPlot(WR.key,"area",showLegend=TRUE)
> alkPlot(WR.key,"area",pal="gray")
> alkPlot(WR.key,"lines")
> alkPlot(WR.key,"lines",pal="gray")
> alkPlot(WR.key,"lines",showLegend=TRUE)
> alkPlot(WR.key,"splines")
> alkPlot(WR.key,"splines",span=0.2)
> alkPlot(WR.key,"splines",pal="gray",showLegend=TRUE)
> alkPlot(WR.key,"bubble")
> alkPlot(WR.key,"bubble",grid=FALSE)
> alkPlot(WR.key,"bubble",grid="blue")
> alkPlot(WR.key,"bubble",grid=rgb(0,0,0,0.2),col=rgb(0,0,0,0.5))
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>