【发布时间】:2014-05-05 01:16:38
【问题描述】:
我在网站上的众多类似但不完全相同的问题中找不到答案。假设我在变量中有一个字符串,它是我要使用的绘图表达式的直接表示,例如"R^2"。如何将其替换为 expression 以便将其呈现为 plotmath?我会疯狂尝试每一种组合,但我无法让它发挥作用......
# 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 ) ) ) )
【问题讨论】:
标签: r graphics plot expression plotmath