0
我无法在网站上的众多相似但不完全相同的问题中找到答案。假设我在变量中有一个字符串,它是我想要使用的plotmath表达式的直接表示,例如, "R^2"
。我该如何将它替换成expression
,以便它可以绘制为阴谋?我要疯了尝试各种组合,但我不能得到它的工作...将表情字符串替换为表达式
# What I want...
mn <- "R^2"
# Using expression directly to show what I'd like to get
plot(1 , main = expression(R^2))
# What I tried to substitute the value of 'mn' into an expression
plot(1 , main = expression(mn))
plot(1 , main = bquote(.(mn)))
plot(1 , main = bquote(paste(.(mn))))
plot(1 , main = do.call(expression , list(mn)))
plot(1 , main = do.call(expression , list(bquote(.(mn)))))
plot(1 , main = do.call(expression , list(bquote(paste(.(mn)))))) #getting silly
plot(1 , main = deparse(substitute(mn , list(mn = mn))))
Garrg。我真的想给自己打气。非常感谢你!!!! –
这似乎是一个很好的例子,其中''parse()'真的没有好的选择,'fortune :: fortune(106)'暗示的例外之一。 –