将回归线(以及拟合优度统计)添加到散点图 [英] Add regression line (and goodness-of-fit stats) to scatterplot

查看:255
本文介绍了将回归线(以及拟合优度统计)添加到散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查看其他stackoverflow帖子之后,我尝试使用以下方式向散点图添加回归线:

After reviewing other stackoverflow posts, I am attempting to add a regression line to my scatter plot with:

plot(subdata2$PeakToGone, subdata2$NO3_AVG, xlim = c(0, 70))
abline(lm(PeakToGone~NO3_AVG, data = subdata2))

但是,它没有显示该行.我还想将lm中的R ^ 2,RMSE和p值添加为绘图上的文本.

However, it is not showing the line. I would also like to add the R^2, RMSE, and p-value from lm as text on the plot.

如何将回归线以及这些拟合优度统计信息添加到绘图中?

How can I add the regression line to the plot, along with these goodness-of-fit stats?

推荐答案

默认情况下,plot将第一个参数视为x,将第二个参数视为y.尝试

By default, plot regards the 1st param as x and the 2nd as y. Try

plot(y = subdata2$PeakToGone, x = subdata2$NO3_AVG, xlim = c(0, 70))
abline(lm(PeakToGone~NO3_AVG, data = subdata2))

,现在看该行是否可见.您会找到第二个问题的答案

and look if the line is visible, now. You'll find an answer to your 2nd question here.

这篇关于将回归线(以及拟合优度统计)添加到散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆