提取r图例的系数数字

时间:2013-06-14 18:31:26

标签: r plot legend

我试图在简单的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)

1 个答案:

答案 0 :(得分:4)

paste0("Slope = ", coef(mod)[2])