This document provides an introduction to marine food web analyses. The tutorial targets students and scientists in marine biology and ecology with previous knowledge of the R software.
It is the companion tutorial for the paper: Disentangling temporal food web dynamics facilitates understanding of ecosystem functioning by S. Kortsch, R. Frelat, L. Pecuchet, P. Olivier, I. Putnis, E. Bonsdorff, H. Ojaveer, I. Jurgensone, S. Strāķe, G. Rubene, Ē. Krūze, and M. Nordström, in review. More details about data and methodology can be found in the Material and Methods section of the paper and in the supplementary material. For example, definitions and equations of metrics can be found in Appendix S6: Table S1. The raw food web dataset can be found on Dryad, DOI:10.5061/dryad.6t1g1jwwn.
Please also consult the tutorial by Ognyanova, K. (2016) Network analysis with R and igraph: NetSci X Tutorial for a detailed introduction to network analysis in R.
If you get an error message, check that the R packages
fluxweb have been installed correctly. If not, use the command:
The metaweb food web of the Gulf of Riga is available as the Rdata file
BalticFW.Rdata, available for download here.
Using the Gulf of Riga food web and this script, you will learn how to compute different weighted and unweighted network metrics to describe food webs.
Make sure the file
BalticFW.Rdata is in your working directory, then load it in R.
The Rdata file contains two objects:
net which is the
igraph network of the Gulf of Riga food web, and
info which is a
data.frame containing information about each taxon. It also contains three custom-written functions that will be used in this script.
##  34
##  207
net has 34 nodes and 207 trophic links.
##  34 10
##  "species" "fg" "nbY" "meanB" "taxon" ##  "met.types" "org.type" "bodymasses" "losses" "efficiencies"
info has 34 rows corresponding to the 34 nodes or taxa in the metaweb; and 10 variables which are:
We will plot the food web using a custom-written function called
plotfw, but first we will assign colors to the nodes depending on which functional group they belong to.
# See the functional group categories levels(info$fg)
##  "Benthos" "Detritus" "Fish" "Phytoplankton" ##  "Zooplankton"
# Color the functional groups colFG<- c("orange", "khaki", "blue", "green", "cyan") # Assign the colors to each node (taxon) info$colfg <- colFG[as.numeric(info$fg)] # Plot the foodweb # Nodes are colored (col) according to functional group # Links (edge) size is reduced with edge.width and edge.arrow.size plotfw(net, col=info$colfg, edge.width=0.3, edge.arrow.size=0.3)
degree() returns the number of links per node (in-degree, out-degree or both). This is useful to quickly check the food web. For example, we can identify which are the basal species (no prey, i.e. 0 in-degree) and the top predators (no predators, i.e. 0 out-degree).
# basal species V(net)$name[degree(net, mode="in")==0]
##  "Autotroph" "Mixotroph" "Detritus"
# top predators V(net)$name[degree(net, mode="out")==0]
##  "Gadus morhua"
Three nodes classified as basal taxa: autotroph phytoplankon, mixotroph phytoplankton, and detritus. Only one species, cod (Gadus morhua), does not have any predators in our food web, and hence is the only top predator.
We can also plot the food web as an interaction matrix (called adjacency matrix), where the columns are the consumers and the rows the resources.
netmatrix <- get.adjacency(net, sparse=F) heatmap(netmatrix, Rowv=NA, Colv=NA, scale="none")