问题
I am plotting some data series along with regression lines using this code:
ggplot(dt1.melt, aes(x=lower, y=value, group=variable, colour=variable)) +
geom_point(shape=1) +
geom_smooth(method=lm,
se=FALSE)
However, I need to constrain the regression line to be through the origin for all series - in the same way as abline(lm(Q75~-1+lower,data=dt1))
would achieve on a standard R plot.
Can anyone explain how to do this in ggplot
?
回答1:
You need to specify this in the formula
argument to geom_smooth
:
... + geom_smooth(method=lm, se=FALSE, formula=y~x-1)
来源:https://stackoverflow.com/questions/12651156/plotting-a-regression-line-through-the-origin