如何使用 plotweb 二分体中的 ifelse() 语句根据交互值更改交互的颜色?

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

您好,我在尝试让 ifelse 语句在 plotweb 函数(从 bipartite)中工作时遇到问题,以根据每个单元格中的交互总量为交互着色矩阵。我对高条形颜色也有同样的问题,但是因为只有几个值和一个向量,所以很容易手动编码。

这是我正在使用的代码,我想将大于 15 的交互着色为深绿松石色,并将其余部分保持为默认灰色 (grey80)。

我尝试了很多不同的语句,但我似乎无法弄清楚要在 [] 中放入什么来表示函数遍历每个单独的单元格并应用语句而不是对它们求和,elem,elem似乎也不起作用。附件是当前函数输出的图片

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

作为参考,我已经让 ifelse 语句在 plotweb 函数中正常运行,当在较低级别中只有一个物种时附有示例和代码:

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)

需要注意的是 col.interaction 颜色矩阵应该转置。

这是一个我相信您会发现有用的示例:

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