2017-02-03 79 views
3

我想知道mtext()有什么问题,我无法获得正确显示在我的图上面的数字GR plot中的mtext()

这里是我的R代码里面:

G <- .3333 ## but G can be anything as it comes from a function 

curve(dnorm(x),-3,3) 
mtext(expression(paste("Medium: ",bold('CT'[12])," = ", round(G,2))),line=3) 
+0

round返回0.3333的数字。你需要这个价值作为一个角色或者组成它。你不能只输入: curve(dnorm(x), - 3,3) mtext(expression(paste(“Medium:”,bold('CT'[12]),“=”,“.3333” )),线= 3)而不是? –

+0

David,其实.3333来自一个函数,所以它可以变化! – rnorouzian

+0

好吧,似乎我迷路了,我的不好 –

回答

3

您可以使用bquote.()(这是用来包括在表达式中的变量)本:

G <- 0.3333 
curve(dnorm(x),-3,3) 
mtext(bquote(paste("Medium: ",bold('CT'[12])," = ", .(round(G,3)))),line=3) 

这给:

enter image description here

+0

你非常欢迎,很高兴我能帮上忙。这听起来像是一个可以从中受益的单独问题。您是否介意将该问题作为新问题发布,以便我们将问题保留为独特的实体? – LyzandeR