在这种情况下,plotmath 无法将调用列表强制转换为表达式。
> cs <- c(bquote(theta == .(a)),bquote(theta == .(a)))
> cs
[[1]]
theta == 123
[[2]]
theta == 123
> sapply(cs, class)
[1] "call" "call"
你可以通过自己强制转换表达式来使其工作:
> c(as.expression(bquote(theta == .(a))), as.expression(bquote(theta == .(a))))
expression(theta == 123, theta == 123)
> plot(1,1)
> legend('bottomleft',legend= c(as.expression(bquote(theta == .(a))),
+ as.expression(bquote(theta == .(a)))))
另一种方法是使用`sapply`强制将原始的调用列表转换为表达式:
Another way is to coerce the original list of calls to expressions using sapply
:
plot(1,1)
legend("bottomleft",
sapply(c(bquote(theta == .(a)), bquote(theta == .(a))), as.expression))