這是因爲c
- 函數不能連接通過bquote
返回的對象類型的多個實例。大多數人認爲bquote
返回R表達式,但它不。它返回調用並且不會連接成列表。您需要將expression
函數應用於通過多次調用返回到bquote
的項目,以將它們放入「表達式」列表中。這是由托馬斯·拉姆利在2005年解釋上Rhelp:
legend("topleft",legend=do.call('expression',
list(bquote(R^{2} == .(r2)),
bquote("P-value" == .(pval))) ),
bty = "n")
![enter image description here](https://i.stack.imgur.com/OlyYg.png)
有另一種方法,如果你wnat建立這種說法傳說,這將允許與c()
一起串起表達式。重新定義bquote返回表達式:
bquote2 <- function (expr, where = parent.frame())
{
unquote <- function(e) if (is.pairlist(e))
as.pairlist(lapply(e, unquote))
else if (length(e) <= 1L)
e
else if (e[[1L]] == as.name("."))
eval(e[[2L]], where)
else as.call(lapply(e, unquote))
as.expression(unquote(substitute(expr)))
}
legend("topleft",
legend=c(bquote2(R^{2} ~ "=" ~.(r2)),
bquote2(paste("P-value =",pval))),
bty = "n")
啊!我認爲它們是語言對象,但我不知道它們可以像這樣組合。 –
如果bquote確實返回了一個表達式,我相信你可以使用'c',因爲表達式列表是類似列表的對象。我會看看我是否可以對其代碼進行修改。 –