How to colour edges for each node a different colour using R bipartite?

  Kiến thức lập trình

I’ve created a bipartite graph using the bipartite package in R, but I want to colour the edges for each of my nodes a different colour so it’s easier to see the different connections.

Sample of my data and code I used:

structure(list(Species = c("Circium arvense", "Hypericum perforatum", 
"Plantago lanceolata", "Trifolium pratense", "Trifolium repens"
), Asteraceae = c(496643L, 295467L, 411L, 420L, 46338L), Apiaceae = c(0L, 
6L, 4L, 1L, 2L), Anacardiaceae = c(220L, 25L, 100L, 118L, 25L
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-5L))

>View(data.sp)
  Species              Asteraceae Apiaceae Anacardiaceae
  <chr>                     <int>    <int>         <int>
1 Circium arvense          496643        0           220
2 Hypericum perforatum     295467        6            25
3 Plantago lanceolata         411        4           100
4 Trifolium pratense          420        1           118
5 Trifolium repens          46338        2            25

# Create bipartite of main flowers and their plant-plant connections
data.mat <- as.matrix(data.sp[,-1])
rownames(data.mat) <- data.sp$Species

plotweb(data.mat, 
        method="normal", 
        text.rot = 90, 
        labsize = 0.9,
        plot.axes = FALSE, 
        y.width.low = 0.05,
        bor.col.interaction = "NA",
        col.high = "#58D68D",
        col.interaction = "#ffd450",
        col.low = "#85C1E9")

enter image description here

Yes it looks ugly but bare with me – my goal here is to make each of the blue nodes have their own unique colours to their edges. For example, all the connections from Circium arvense can be pink, all the Hypericum perforatum can be yellow, etc. Is this possible??

LEAVE A COMMENT