How do I change color of interactions based on interaction value using an ifelse() statement in an plotweb bipartite?

Justin Luong

Hi I am having trouble trying to get ifelse statements to work in a plotweb fuction (from bipartite) to color interaction based on the total quantity of interaction of each cell in the matrix. I had the same problem with the high bar colors, but since there were only a few values and one vector, it was easy to manually code.

Here is the code I am using, I want to color interactions greater than 15 as dark turquoise and keep the rest as default grey (grey80).

I have tried many different statements but I cant seem how to figure out what to put in the [,] to signify for the function to go through every individual cell and apply the statement instead of summing them, elem,elem also doesn't seem to work. Attached is a picture of the function's output currently

plotweb(LadyNet, 
        abuns.type='additional',
        arrow="up.center",
        text.rot=90,
        col.low=c("olivedrab3"),
        col.interaction =(ifelse(LadyNet[,] < 15,'grey80','darkturquoise')), 
        col.high = c("grey10","#FF0000","grey10","#FF0000","grey10","#FF0000","grey10","grey10","grey10"),
        high.lab.dis = 0,
        ybig=1.2,
        y.width.high = .06,
        high.spacing = 0.011, 
        y.lim = c(-1,2))

Picture of Output

COCCAL  COCSEP  CYCPOL  CYCSAN  EXOFAS  HIPCON  PSYVIG  SCY1    SCYMAR
Acmispon glaber 0   1   0   1   0   0   0   0   0
Ambrosia psilostachya   1   36  0   24  0   6   0   0   0
Artemisia douglasiana   0   0   0   1   0   1   0   0   0
Asclepias fascicularis  0   5   0   4   0   2   0   0   0
Avena fatua 6   10  0   0   0   4   0   0   0
Baccharis pilularis 9   76  0   38  0   27  0   1   0
Baccharis salicifolia   0   2   0   0   0   0   0   0   0
Bromus diandrus 1   8   0   0   0   4   0   0   0
Capsicum annuum 0   0   0   0   0   0   0   0   1
Chenopodium murale  0   1   0   0   0   0   0   0   0
Croton californicus 3   20  0   13  0   54  4   0   0
DEAD WOOD   0   1   0   0   0   0   0   0   0
Distichilis spicata 0   1   0   0   0   0   0   0   0
Echium candicans    0   1   0   3   0   0   0   0   0
Eleocharis acicularis   0   1   0   0   0   0   0   0   0
Encelia californica 1   1   0   3   0   2   0   0   0
Epilobium canum 0   0   0   1   0   0   0   0   0
Erigeron bonariensis    0   4   0   0   0   0   0   0   0
Erigeron canadensis 0   17  0   10  0   2   0   0   0
Erigeron sumatrensis    0   13  0   0   0   1   0   0   0
Eriophyllum confertiflorum  1   10  0   0   0   1   0   0   0
Fence   0   0   0   1   0   0   0   0   0
Festuca perennis    0   1   0   0   0   2   0   0   0
Gambelium speciosa  0   0   0   0   0   1   0   0   0
Geranium dissectum  0   0   0   3   0   0   0   0   0
GROUND  0   1   0   1   0   0   0   0   0
Helminthotheca echioides    0   1   2   17  0   1   0   0   0
Heterotheca grandiflora 2   92  0   12  0   7   1   0   0
Hirschfieldia incana    0   3   0   0   0   1   0   0   0
Juncus patens   0   1   0   0   0   0   0   0   0
Laennecia coulteri  1   65  0   2   0   3   0   0   0
Lobularia maritima  1   1   0   0   0   0   0   0   0
Morus sp.   0   0   0   1   0   0   0   0   0
NoPicture   4   3   0   3   3   2   3   0   0
Oxalis pes-caprae   4   6   0   0   0   2   0   0   0
Pennisetum clandestinum 1   5   0   0   0   0   0   0   0
Polygonum arenastrum    0   1   0   0   0   0   0   0   0
Raphanus sativus    0   1   0   0   0   0   0   0   0
ROCK    0   0   0   1   0   0   0   0   0
Rumex crispus   0   1   0   0   0   0   0   0   0
Rumex salicifolius  0   0   0   3   0   0   0   0   0
Salsola tragus  1   6   0   1   0   1   0   0   0
Salvia leucophylla  0   1   0   0   0   1   0   0   0
Schenoplectus americanus    0   1   0   0   0   0   0   0   0
Solanum nigrum  0   0   0   0   0   1   0   0   0
Sonchus arvensis    0   1   0   0   0   0   0   0   0
Spinacia oleracea   0   0   0   0   0   0   1   0   0
Stipa pulchra   0   1   0   0   0   0   0   0   0
Symphiotrichum subulatum    0   88  0   7   0   3   0   0   0
THATCH  1   3   0   0   0   4   0   0   0
Verbena lasiostachys    1   9   0   0   0   2   0   0   0

For Reference, I have gotten the ifelse statement to function properly in the plotweb function when there was only one species in the lower level attached is an example along with the code:

RNET

plotweb(rnet, 
        abuns.type='additional',
        arrow="down.center",
        text.rot=90,  
        col.low=c("olivedrab3"),
        col.interaction =(ifelse(rnet[1,] < 12,'grey80','darkturquoise')), 
        col.high = (ifelse(rnet[1,] < 12,'grey10','darkturquoise')),
        high.lab.dis = 0,
        ybig=1.2,
        y.width.high = .06, 
        high.spacing = 0.011)
missuse

One thing to note is that the col.interaction color matrix should be transposed.

Here is an example that I trust you will find useful:

library(bipartite)
library(grDevices)

plotweb(df, 
    abuns.type='additional',
    arrow="up.center",
    text.rot=90,
    col.low=c("olivedrab3"),
    col.interaction = t(ifelse(df[,] < 15,
                             adjustcolor('grey80', alpha.f = 0.5), #add alpha to colors
                             adjustcolor('darkturquoise', alpha.f = 0.5))), 
    col.high = c("grey10",
                 "#FF0000",
                 "grey10",
                 "#FF0000",
                 "grey10",
                 "#FF0000",
                 "grey10",
                 "grey10",
                 "grey10"),
    bor.col.interaction = NA, #remove the black border color
    high.lab.dis = 0,
    ybig=1.2,
    y.width.high = .06,
    high.spacing = 0.011, 
    y.lim = c(-1,2))

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I change the color of an infobox in shinydashboard based on a string, not a value?

How do I change a value of a variable using an if else statement?

How do I change the color of a column based on the color of other column?

How do I change the color of a cell under a conditional statement?

How can I change the background color of a row based on the value using HTML, CSS and JavaScript?

How to change a value from a column using ifelse()

How can I change ChartJS line color based on the value?

How to change color for the numbers based on its value using javascript and react?

How to change color of text based on text-value by using css?

How to change text color based on a dynamic value using Angularjs directives?

How to change the text color based on a value using php and html?

How do i change input field background color based on onclick?

How do I change the color of a row based on specific dates?

How do i update multiple records using MERGE statement and use max(column_value) based on previously updated records in the same statement?

How can I do an if statement based on option value? [Liquid / Shopify]

How do I change this value using regex?

Angular: How do I change value based on key value

How do I change the color on my noUiSliders depending on the value it currently is at?

How do I change color's hue, saturation, or value in Flutter?

How do I change the options from a dropdownlist based on the selected value from another dropdownlist using ajax?

How do I create multiple flag columns based on multiple columns with NA Values using ifelse?

How do I create multiple variables using ifelse based on matching names of other variables?

Using dircolors, how do I change the color of my subversion folders

How do I change the background color of the ActionBar of an ActionBarActivity using XML?

How do I change a tab background color when using TabLayout?

How do I change the color of a stroke using the click of a button in Javascript?

How do I change the background color of a Table using code? WatchKit

how do i change color of label in wpf using vb

How do I change the background color of div using jquery?