r - 如何用公式规范绘制回归线

标签 r ggplot2 formula lm

我正在尝试绘制一条穿过原点的回归线。我使用以下代码:

library(ggplot2)
library(ISwR)
thuesen
cc <- complete.cases(thuesen)
tcc <- thuesen[cc,]
attach(tcc)
m <- lm(short.velocity~blood.glucose -1)
m
graph <- ggplot(data=tcc, aes(x=blood.glucose, y=short.velocity)) + geom_point()
graph + geom_smooth(method="lm", formula=m)
Error in model.frame.lm(formula = formula, data = data, weights = weight,  : 
objet 'weight' introuvable

我不明白这个错误消息,有人能解决这个问题吗?

最佳答案

要在ggplot2中使用相同的公式:

graph + geom_smooth(method="lm", formula=y~x-1)

enter image description here

关于r - 如何用公式规范绘制回归线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26828480/

相关文章:

R : add an average line to an existing plot

r - 估计 glmnet 中的许多交互项

math - 为什么有 3 个相互冲突的 OpenCV 相机标定公式?

r - 使用字符串作为dplyr中的过滤器?

R:回测交易策略。 quantmod 和 R 的初学者

r - as.Date 不保留 R 中的时间

r - 将多个函数传递给 purrr :map

r - 如何重复 ggplot 图例中的符号以获得更好的符号 View ?

r - 密度曲线下的阴影(填充或颜色)面积(按分位数)

基于标准的 Excel 索引