GyrLu
GyrLu

Reputation: 33

how to plot regression line with specification of formula

I'm trying to plot a regression line that passes through the origin. I use the following code:

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

I don't understand this error message, has anyone a solution to this issue ?

Upvotes: 2

Views: 84

Answers (1)

agstudy
agstudy

Reputation: 121608

To use the same formula within ggplot2:

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

enter image description here

Upvotes: 2

Related Questions