1

我试图在一个简单的 R 图中获取图例以报告系数(即斜率),而无需手动提取值。有谁知道如何对图例进行编码,以便它显示值而不是命令?谢谢

y <- rnorm(100)
x <- sample(rnorm(100), 100, replace = TRUE)
plot(x, y)
mod <- lm(y ~x)
abline(lm(y~x))
legend("topleft", "Slope = coef(mod)[2]", col = "black", pch = 15, cex = .8)
4

1 回答 1

4
paste0("Slope = ", coef(mod)[2])
于 2013-06-14T18:32:48.860 回答