You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用geom_smooth拟合无截距线性回归遇异常:仍出现截距求助

解决geom_smooth无截距但回归方程仍显示截距的问题
  • 问题根源:你只给geom_smooth()设置了无截距公式,但stat_regline_equation()默认用的是带截距的y~x公式,两者参数不同步,所以方程里还是会显示截距项。
  • 修复方法:给stat_regline_equation()也加上相同的无截距公式,比如formula = y~x+0或者formula = y~x-1,让它和geom_smooth()使用一致的拟合规则。
  • 修改后的完整代码:
library("tidyverse")
mtcars %>%
  ggplot(aes(disp, hp)) +
  geom_point() +
  geom_smooth(method="lm", formula=y~x+0)+
  stat_regline_equation(label.y = 300, formula=y~x+0)+
  stat_cor(label.y = 250) +
  theme_bw()
  • 额外说明:stat_cor()负责输出相关系数,和回归模型的截距设置无关,无需调整它的参数。

内容的提问来源于stack exchange,提问作者Elizabeth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 16:14:55