我试图在简单的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)
答案 0 :(得分:4)
paste0("Slope = ", coef(mod)[2])