Data visualization (in R)

Drawing a trophic network (part 2)

Posted in Ecology by Timothée on July 6, 2010

Following discussion on the comments of the previous post, I thought about how it was possible to draw links going in several directions (i.e. there are no ‘clear’ differences between the levels, and species from level n can interact with species of level n, n+1, n-1, n±k, etc).

This is now done, with a code that is as inelegant as humanly possible. Also, the way to lay the different nodes on the graph (i.e. their ‘trophic level’) should be calculated with a proper method, but (i) I am not a specialist of these metrics, and (ii) it is way too late to do any decent bibliographical research to look them up.

The procedure I use here is quite horrible. I randomly reorder the matrix, and compute the trophic position by elevating each species whenever it eats another species. I repeat this a couple time, and then average the trophic position for each species. The x position is a simple random value, which means that you will probably need to do the launch the code a couple times to get a decent looking network.

The R code can be downloaded here.

About these ads
Tagged with:

6 Responses

Subscribe to comments with RSS.

  1. [...] little flowers as well (and carnivorous flowers are possible as well). See the R code here, and read the accompanying post. This entry was written by Timothée, posted on 06/07/2010 at 18:58, filed under Tech and tagged [...]

  2. Petr said, on July 8, 2010 at 8:50 am

    you can plot this simply by using igraph package:

    library(igraph)
    G=graph.adjacency(net) # from matrix to graphplot(graph.adjacency(net),layout=layout.fruchterman.reingold,vertex.names=V(G)$name)

  3. Petr said, on July 8, 2010 at 8:52 am

    errata:

    library(igraph)

    G=graph.adjacency(net) # from matrix to graph

    plot(graph.adjacency(net),layout=layout.fruchterman.reingold,vertex.names=V(G)$name)

    • Timothée said, on July 8, 2010 at 12:03 pm

      After playing a little bit with what you suggest, I’m afraid it is not a good solution…

      The fact is that with my current code, the vertical position of each node is important (e.g. TP is higher because it is upper in the trophic chain). The layout in igraph seems to position the nodes in a unpredictable way…

      • Petr said, on July 8, 2010 at 12:25 pm

        You can use different algorithm for layout calculation
        layout.reingold.tilford is suitable to show the hierarchy (you can set root node)

  4. Timothée said, on July 8, 2010 at 9:37 am

    I sure can

    I have never been comfortable with the igraph library, though


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: