我正在尝试绘制一条穿过原点的回归线。我使用以下代码:
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)
关于r - 如何用公式规范绘制回归线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26828480/