如何在plotweb bipartite中使用ifelse()语句基于交互值更改交互的颜色? [英] How do I change color of interactions based on interaction value using an ifelse() statement in an plotweb bipartite?

查看:277
本文介绍了如何在plotweb bipartite中使用ifelse()语句基于交互值更改交互的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让ifelse语句在plotweb函数(来自 bipartite )中工作以根据矩阵中每个单元格的交互作用总数进行颜色交互。我对高色条的颜色也有同样的问题,但是由于只有几个值和一个向量,因此手动编码很容易。

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.

这是我的代码在使用中,我想将大于15的交互颜色设置为深蓝绿色,并将其余颜色设置为默认的灰色(grey80)。

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

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

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

当仅附有一个较低级别的物种时,我已经获得了ifelse语句在plotweb函数中正常运行的示例以及代码:

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)


推荐答案

要注意的一件事是, col.interaction 颜色矩阵应

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

这篇关于如何在plotweb bipartite中使用ifelse()语句基于交互值更改交互的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆