ifelse()在Legend R中不起作用

时间:2017-02-08 02:58:31

标签: r plot

我想知道为什么我ifelse()中的legend()无法正常工作?我收到以下错误:

**Error in rep(no, length.out = length(ans)) : attempt to replicate an object of type 'language'**

这是我的 R代码:

Gi <- 2      
plot(1:10,ty="n")  

legend("topright",
  legend=ifelse(Gi>1,      ## ! ifelse() Not Working HERE ! ##
    bquote(paste("Evidence favors A: ",bold('CT'[10]),
                " = ", .(round(Gi,3)))),
    bquote(paste("Evidence favors B: ",bold('CT'[01]),
                " = ", .(round(1/Gi,3))))),
  pch = " ",cex=1.5, bty="n", inset=c(.005,-.05))

1 个答案:

答案 0 :(得分:-1)

我不太确定bquote()函数对你有什么作用,但是我稍微更改了你的代码并将图例显示在你的情节上。

这是代码,如果您认为它是正确的,请告诉我。

Gi <- 2      
plot(1:10,ty="n")  

l <- ifelse(Gi>1, paste0("Evidence favors A: ",'CT[10]'," = ", (round(Gi,3))),
       paste0("Evidence favors B: ",'CT[01]'," = ",(round(1/Gi,3))))

legend("topright", legend=l, pch = " ",cex=1.5, bty="n", inset=c(.005,-.05))