How can I get the same color and interaction line of each box in bipartite

171 Views Asked by At

When I make a bipartite plot, the color of each lower box and the interaction color between the lower boxes and the higher boxes are different. BUT I want to make the color of the lower box and the color of interaction the same.

The code below is the code before modification.

library(RColorBrewer)
library(bipartite)

# generating_bipartite 
bip_matrix <- table(bip_data$higher, bip_data$lower)

colP = rainbow(length(unique(c(bip_data$higher, bip_data$lower))))


plotweb(bip_matrix, 
        method = 'normal', 
        col.high = colP, 
        col.low = 'black', 
        col.interaction = colP, 
        bor.col.interaction = colP, 
        bor.col.high = colP, 
        bor.col.low = 'black', 
        high.lablength = NULL, 
        low.lablength = NULL, 
        text.rot = 90, 
        text.high.col = 'black', 
        text.low.col='black', 
        low.lab.dis=0 )

The picture is the example that I want to be.

enter image description here

and this is my bipartite.

enter image description here

So I tried to color each element directly through the code, but the result kept getting mixed up...

1

There are 1 best solutions below

0
Adlai Herrera On

Figured out how to do this!

plotweb(bird_food_mat2,text.rot=90,col.interaction =c("darkseagreen2","cadetblue2","tan2","lightpink","peachpuff","plum1"), col.high = c("darkseagreen2","cadetblue2","tan2","lightpink","peachpuff","plum1"))

You need to include the appropriate # of colors, so I had 6 predator bird species (hence 6 colors). All you need is col.interaction and col.high. You just need to ensure that the colors are in the same order.

The only difference that might give you trouble is that your predator species (I'm assuming) are on the left-hand side rather than the right. I had my bird species(predators) on the right, and my prey species on the left, much like the image you referenced from the Spain Metabarcoding article. You may need to switch the columns in your matrix, so perhaps it would look like this?

table(bip_data$lower,bip_data$higher)

Hope that helps! I've included an example of my graph.

https://i.stack.imgur.com/NPoEL.png