3

我很难使用expression()将文本添加到绘图的功能。具体来说,我一直无法在表达式中使用对对象的调用结果。这是一个例子:

例子

set.seed(1)
x <- 1:100
y <- 2*x + 3 + rnorm(length(x), sd=10)

fit <- lm(y~x)
plot(y~x)
abline(fit)
text(50,200, labels=expression(paste(alpha, "=", round(fit$coeff[1],3), "; ", beta, "=", round(fit$coeff[2],3), "; ", R^2, "=", round(summary(fit)$r.squared,2))))

在此处输入图像描述 我希望文本看起来像图中用红色写的那样。任何帮助将不胜感激。

4

1 回答 1

3

试试?bquote

text(50,200, label=bquote(alpha == .(fit$coeff[1]) ~ "; "~ beta == .(fit$coeff[2])~"; "~R^2 ==  .(summary(fit)$r.squared)))
于 2013-04-11T13:09:37.467 回答