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

拈花ヽ惹草 提交于 2019-12-25 01:34:40

问题


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))

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:

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)

回答1:


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))



来源:https://stackoverflow.com/questions/51625098/how-do-i-change-color-of-interactions-based-on-interaction-value-using-an-ifelse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!