【问题标题】:mtext() in R plotR图中的mtext()
【发布时间】:2017-02-04 01:27:36
【问题描述】:

我想知道 mtext() 有什么问题,我无法在我的绘图上方正确显示数字 G

这是我的 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)

【问题讨论】:

  • round 返回一个数字,即 0.3333。您需要将值作为字符或组合它。你不能直接输入:curve(dnorm(x),-3,3) mtext(expression(paste("Medium: ",bold('CT'[12])," = ", ".3333")) ,line=3) 代替?
  • 大卫,其实.3333来自一个函数,所以它可以变化!
  • 好吧,我好像迷路了,我的错

标签: r plot


【解决方案1】:

您可以为此使用bquote.()(用于在表达式中包含变量):

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

这给出了:

【讨论】:

  • 不客气,很高兴我能帮上忙。这听起来像是一个单独的问题,有人可以从中受益。您介意将其作为一个新问题发布,以便我们将问题保留为唯一实体吗?
猜你喜欢
  • 2022-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-10
  • 1970-01-01
相关资源
最近更新 更多