在R中使用直方图中mtext()中使用的plotmat中的变量

时间:2013-10-10 09:54:57

标签: r histogram plotmath

    m <- mean(outcome[, 11], na.rm = TRUE)

   hist(df[, 11], main = "",xlab="", ylab="", xlim = c(0,as.integer(range(df[,11], na.rm=TRUE))[-1]), axes = FALSE)
   axis(side = 1, at = c(10,15,20))
   axis(side = 2, at = c(0,200,400,600), labels=c(0,200,'',600),pos=c(as.integer(range(df[,23], na.rm=TRUE))[-2],0))
   mtext(expression(paste(plain("My Title("), hat(X)== substitute(m) , plain(")"))), side=3, line= 2, cex = 1, at=14)

如何在mtext中使用m的值?

此链接here 提出了两种适用于text()但不适用于mtext()的方法。

1 个答案:

答案 0 :(得分:1)

我认为line = 2会使其从绘图区域的边缘打印出来。尝试使用bquote而不是paste():

 mtext(bquote( plain("My Title(")* hat(X) == .(m) * plain(")")), 
       side=3,  cex = 1, at=14)

当您放弃paste()策略时,您需要使用波浪号(空格)和星号(无空格)来连接组件。