2 x在绘图文本中连接字符串和表达式

时间:2014-07-21 21:06:03

标签: r plot expression title

this thread相似,但这次我需要加倍。

以下是一个例子:

x1 <- 0
x2 <- 1
plot(c(0,1),c(0,0), type="l", axes=FALSE, main="", ylab="", xlab="")
axis(1, at=c(0, 1), labels=c(bquote(gamma~" = " ~ .(x1)), expression(delta~" = " ~ .(x2))), pos=-.01, xpd=TRUE)

情节标签应该是:

 Gamma = 0     Delta = 1

但是,看看你自己跑,你得到:

 Gamma = 0     Delta = .(x2)    

请注意,以下代码无法按预期运行:

axis(1, at=c(0, 1), labels=c(bquote(gamma~" = " ~ .(x1)), bquote(delta~" = " ~ .(x2)), pos=-.01, xpd=TRUE)

它产生:

gamma ~ " = " ~ 0     delta ~ " = " ~ 1

谢谢。

1 个答案:

答案 0 :(得分:0)

怎么样

axis(1, labels=eval(bquote(expression(gamma == .(x1),delta == .(x2)))),
    at=c(0, 1), pos=-.01, xpd=TRUE) 

enter image description here