In the last few weeks, I started focusing more on more of trophic systems with three levels, by adding « pretty flowers » to the classical system in which « cute bunnies » try to survive « rabid foxes ». I wanted something to visualize the resulting trophic network. The R community already came up with the excellent bipartite library, but it is focused on two mode networks (hence *bi*partite). So I came up with a little R function called `draw.mnet`

(which stands for *draw a multiple-levels network*).

This function accepts as arguments a list of matrices (each matrix giving the strength of the links within one level). The consumers (i.e. upper level) are in the rows, and the resources are in columns. The first matrix of the list is the upper one (i.e. the top-predators are in the rows of the first matrix). It is recommended that all of the values within the matrices are in the 0-1 range.

The intensity of the link (if available) is used either to give the darkness of the polygon linking the different species (`poly=TRUE`

) or the width of the link (`poly=FALSE`

). A picture of the result (with polygons) might help you understand. Colors of the species (nodes of the network) are given by the `spbg`

vector, which must contains as many entries as there are levels in your network (but do not worry, there is a nice looking default vector).

Now, I’m sure there are about a million ways to make this function better (first thing to come : sorting the matrices in any meaningful way). In its current state, it is still good enough to provide decent looking networks for presentations or reports.

You can download the R file (with a tri-trophic randomized network example), and tell me what you think about it!

**Edit**

There is now a new code (more of a « proof of concept ») to acknowledge the case mentioned in the comments, where the rabid foxes go green, and start eating little flowers as well (and carnivorous flowers are possible as well). See the R code here, and read the accompanying post.

*Related*

To

**leave a comment** for the author, please follow the link and comment on their blog:

** Timothée Poisot » R**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as:

Data science,

Big Data, R jobs, visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...

**Tags:** Ecology, R, Tech, trophic networks, visualization