More food web plotting with R

Food web for Otago Harbor, NZ:otagopredweb1

One of the many things I have been trying to figure out is how to plot food webs in a manner that makes sense, using the igraph package in R, see here. I finally understand the code required to lay out the web in a sensible manner, that is by trophic level. It turns out to be a relatively simple process. Rather than using one of the provided layouts; circle, kamada kawai, fruchterman reingold, etc, you can set the coordinates of each node.

Thus, if you set the y coordinate to trophic level, and set the x coordinate to a value randomly drawn from a uniform distribution you get the above layout. The easiest way to get trophic levels is with the NetIndices package. TrophInd() is the function, it takes an adjacency matrix as an input and the output is the trophic level of each node, along with an index of omnivory.

lay<-matrix(nrow=123,ncol=2) # create a matrix with one column as runif, the other as trophic level

Here “otagopred” is the graph object for the above plot, “predweb.adj[[1]]” is a list of several adjacency matrices for a set of food web data that I have.

I was also able to do some neat stuff with this web, like coloring some of the parasite links differently.

otagoparaweb2Where blue links are macroparasitic interactions, red are trophically transmitted parasites, and black is commensal interactions.

E(otagoedge)[wotagolink[,3]==6]$color<-"blue" #macroparasite
E(otagoedge)[wotagolink[,3]==12]$color<-"red" #trophic transmitted parasite



Another way to plot webs is with the relatively new cheddar package (I am planning a more detailed post about it to come soon). There are a few functions for plotting webs using the cheddar package, but my favorite is PlotWebByLevel(). One nice thing about cheddar is the fact that the functions are named quite nicely.



Nice simple and clean. It even provides a title for you.

Cheddar also comes with a few fun food web datasets, like this one from Tuesday Lake circa 1986 (they also have 1984).

This entry was posted in Research and tagged , , . Bookmark the permalink.

2 Responses to More food web plotting with R

  1. Pingback: Oikos, food web methods, and PARASITES! | Assembling my Network

  2. Pingback: Blogroll: Assembling my Network | Scientific Gems

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s