library(knitr) ## Global options opts_chunk$set(echo =!TRUE, eval =TRUE, prompt =FALSE, comment =NA, message =FALSE, tidy =FALSE, warnings=FALSE, fig.height=7, fig.width =7)
warn=options()$warn options(warn=-1) library(ggplot2) library(devtools) library(doBy) theme_set(theme_bw()) options(digits=3) options(warn=warn)
FLTag
is being developed as part of the Atlantic Ocean Tropical Tuna Tagging Programme (AOTTP) coordinated by the International Commission for the Conservation of Atlantic Tunas (ICCAT). AOTTP is funded by the European Union and other ICCAT Contracting Parties.
FLTag
is aimed at the statistical analysis and visualisation of large-scale oceanographic fish tagging data with current focus being on bigeye, skipjack and yellowfin tunas. In particular it was developed to calculate the key parameters that
can be derived from tagging data, important in population assessements; e.g mortality, growth and migration rates.
The simplest way to obtain FLTag
is to install it from CRAN by using the following command in the R console:
install.packages("FLTag", repos = "http://cloud.r-project.org/")
The repos options can be changed depending on personal preferences and includes options such as choosing the directories in which to install the packages see help(install.packages) for more details.
FLTag
is part of the FLR
family of packages, so you can install the latest version of the FLR packages using the FLR installation script:
source("http://flr-project.org/R/instFLR.R")
or, if you know you have all the necessary dependencies, directly from the repository:
install.packages(repos="http://flr-project.org/R")
To get help please post your questions or suggestions to the FLR mailing list. Conversations can be started at our scrollbak.io room. Bug reports for individual packages can be submitted using their individual github issues page. So that users may have a better idea of what functions are available, which one to choose, or where to seek help, this section provides a general overview of the package. In particular it highlights the various elements, what they do, and provides some examples of usage. More details are given in later sections.
First, load the FLTag
package:
library(FLTag)
There are example datasets for tag releases and recoveries in FLTag
, which are for used for illustration and as test datasets; alternatively users can load their own tagging data.
data(releases) data(recoveries)
The releases dataset contains details (e.g. location and time) on the releases of tagged tropical tuna species.
head(releases)
Similarly the recoveries data set containts details (e.g. location and time) of when and where those tagged tuna were recovered.
head(recoveries)
In tagging databases there are often strange observations and missing values which we can be cleaned out as follows:
recoveries <- recoveries[!is.na(recoveries$latitude),] recoveries <- recoveries[!is.na(recoveries$longitude),] releases <- releases[!is.na(releases$latitude),] releases <- releases[!is.na(releases$longitude),] releases <- releases[releases$speciescode %in% c('BET','SKJ','YFT'),] releases <- releases[releases$len >=20,]
Plotting when analysing data with FLTag
is best done using ggplot2
, see Grammar of Graphics ^[Wilkinson, L. 1999. The Grammar of Graphics, Springer. doi 10.1007/978-3-642-21551-3_13.]
The ggplot
functions expects a data.frame
for its first argument, data
; then a geometric object geom
that specifies the actual marks put on to a plot and an aesthetic that is "something you can see" have to be provided. Examples of geometic Objects (geom) include points (geom_point, for scatter plots, dot plots, etc), lines (geom_line, for time series, trend lines, etc) and boxplot (geom_boxplot, for, well, boxplots!). Aesthetic mappings are set with the aes() function and, examples include, position (i.e., on the x and y axes), color ("outside" color), fill ("inside" color), shape (of points), linetype and size. Usually the first thing we should do prior to any data analysis is to plot the data.
In the context of oceanic fish tagging data we can use FLTag
to plot the location of conventional tag releases using ggplot2
and also easily add other geographic layers, e.g. for Large Marine Ecosystems and/or the FAD moratorium 2016 which are built-in to FLTag
:
library(ggplot2) world <- map_data('world') data("lme") data("fadmoratorium") ggplot() + geom_polygon(data=world,aes(x=long,y=lat,group=group))+ geom_polygon(data=lme,aes(x=long,y=lat,group=group),color='darkgreen',fill=NA,size=0.5)+ geom_polygon(data=fadmoratorium,aes(x=long,y=lat,group=group),color='darkblue',size=0.5) + coord_fixed(1.3,xlim=c(-60,30),ylim=c(-40,40))+ geom_point(aes(x=longitude,y=latitude,color=speciescode),data=releases[releases$speciescode %in% c('BET','SKJ','YFT'),] ,alpha=0.5,size=0.5) + theme(plot.margin=unit(c(0,0,0,0),"cm"), axis.text.x =element_text(colour="grey20",size=15,face="plain"), axis.text.y=element_text(colour="grey20",size=15,face="plain"), axis.title.y=element_text(size=15))+ xlab("")+ylab("")
Similarly we can plot the spatial distribution of the recovered tuna as follows:
world <- map_data('world') recoveries$speciescode <- releases$speciescode[match(recoveries$specimenid,releases$specimenid)] # assumes the species identified by the tagger during release was correct ggplot() + geom_polygon(data=world,aes(x=long,y=lat,group=group))+ coord_fixed(1.3,xlim=c(-50,30),ylim=c(-40,40))+ geom_point(aes(x=longitude,y=latitude,color=speciescode),data=recoveries[recoveries$speciescode %in% c('BET','SKJ','YFT'),],alpha=1,size=.25)+ theme(plot.margin=unit(c(0,0,0,0),"cm"), axis.text.x =element_text(colour="grey20",size=15,face="plain"), axis.text.y=element_text(colour="grey20",size=15,face="plain"), axis.title.y=element_text(size=15))+ xlab("")+ylab("")
Merging the tag release data to the tag recovery table is then essential for estimating important parameters such as growth, mortality and migration. In the following code the tag release and recovery data are organised in a series of pairs by tag code ID and then grouped by status of release and recovery:
library(doBy) recs <- data.frame(recoveries[,c("specimenid","ctcode1","speciescode","date","latitude","longitude","len")]) dimnames(recs)[[2]][4] <- 'date' rels <- data.frame (releases[,c("specimenid","ctcode1","speciescode","date","latitude","longitude","len")]) dimnames(rels)[[2]][4]<- 'date' all <- merge(recs,rels,all=T) all<- all[all$speciescode %in% c('BET','LTA','SKJ','YFT'),] x <- table(all$ctcode1); x <- x[x==2] all <- all[all$ctcode1 %in% names(x),] all<- orderBy(~ctcode1+speciescode+date,data=all) prob.tags <- c(7124,10410,10585,10374,1093,1013,1039) all <- all[!c(all$ctcode %in% prob.tags),] d_len <- tapply(all$len,all$ctcode,diff) reliable_len <- names(d_len)[d_len >= 0] all$status <- rep(c('release','recovery'),length(all[,1])/2) # LFs of releases versus recoveries ggplot(all[all$speciescode %in% c('BET','LTA','SKJ','YFT'),], aes(x=len,group=status,color=status,fill=status)) + geom_density(alpha=0.5)+ xlim(30,120)+ facet_wrap(~ speciescode, ncol=2)
This allows us to plot length-frenquency distributions of released versus recovered fish giving an idea of growth. Similarly the merged data can be used to plot vectors of migration arrows, between release and recovery, using ggplot2. Note the substantial migrations of skipjack from the Azores to the waters of Senegal:
all1 <- all[all$latitude !=0,] ggplot() + geom_polygon(data=world,aes(x=long,y=lat,group=group)) + coord_fixed(1.3,xlim=c(-60,30),ylim=c(-40,40)) + geom_path(data=all1,aes(x=longitude,y=latitude,group=specimenid,color=speciescode), arrow = arrow(length = unit(0.1,"cm")),size=.25,alpha=.5) + facet_wrap(~ speciescode, ncol=2) + geom_point(data=releases[releases$speciescode %in% c('BET','LTA','SKJ','YFT'),], aes(x=longitude,y=latitude,group=specimenid),color='darkgreen',size=.01) + xlab("")+ylab("")
FLPKG
at the FLPKG
issue page ^[https://github.com/flr/FLPKG/issues], or on the FLR mailing list.FLPKG
can always be installed using the devtools
package, by callinglibrary(devtools) install_github('flr/FLPKG')
r version$version.string
r packageVersion('FLCore')
r # packageVersion('FLPKG')
r date()
r system("git log --pretty=format:'%h' -n 1", intern=TRUE)
Laurence KELL. laurie@kell.es
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.