Creating a network in R using the bipartite package

35 Views Asked by At

I am trying to create a seed dispersal network in R with pre-extinction birds on one side, plant species in the middle, and post-introduction birds on the other side. I want the links connecting the birds and plants to be coloured based on whether the outcome of the interaction is "dispersed" or "destroyed" and I want the nodes to be coloured based on whether the bird is extinct, introduced, or current native. I also want the plants to be ordered by seed size and the birds to be ordered by family. I'm struggling to create the code and to find resources to help me learn.

Here is a sample dataframe:

df <- data.frame(
  bird_species = c("bird1", "bird2", "bird3", "bird1", "bird2", "bird3", "bird1", "bird2", "bird3"),
  plant_species = c("plant1", "plant1", "plant1", "plant2", "plant2", "plant2", "plant3", "plant3", "plant3"),
  outcome = c("destroyed", "dispersed", "dispersed", "dispersed", "destroyed", "dispersed", "destroyed", "destroyed", "dispersed"),
  bird_family = c("family1", "family2", "family3", "family1", "family2", "family3", "family1", "family2", "family3"),
  seed_size = c(1, 2, 3, 2, 1, 3, 3, 2, 1),
  bird_status = c("native", "introduced", "native", "extinct", "native", "introduced", "native", "extinct", "native"),
  frequency = rep(1, 9)
)

pre_network=subset(df, bird_status!= "introduced")
post_network=subset(df, bird_status!="extinct")

I thought the bipartite package would be the best to use, but I couldn't get it to work at all. I tried igraph() but the layout is wrong and I couldn't get all of the elements I wanted. I think bipartite is the better option. I also looked at alluvials in ggplot() and I got it to work but it didn't look as nice as a lot of the papers I saw that used bipartite. I really like fig4 from the paper "Novel plant–frugivore network on Mauritius is unlikely to compensate for the extinction of seed dispersers" by Heinen et al 2013.

Example

0

There are 0 best solutions below