Plotting a regression line through the origin

这一生的挚爱 提交于 2021-02-18 21:13:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!