Thanks John, yes you are right I have add different smooth statements, here is the code from Dennis for my case:
library(ggplot2) ggplot(data = df, aes(x=Var1, y=log(Var2), color=SiteID, group=SiteID)) + geom_point() + geom_smooth(data = subset(df, SiteID != "AL3"), method='lm', formula= y ~ I(1/x), se=FALSE, size=2) + geom_smooth(data = subset(df, SiteID == "AL3"), method = "lm", formula = y ~ log(x), se = FALSE, size = 2) On Sat, Jul 27, 2013 at 9:14 AM, John Kane <jrkrid...@inbox.com> wrote: > I have not tried anything like that but have a look at > www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CDkQFjAC&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F7476022%2Fgeom-point-and-geom-line-for-multiple-datasets-on-same-graph-in-ggplot2&ei=MfHzUej7FoSergG1_ICYAw&usg=AFQjCNH2b72a6un_xAM-PYxC-sUGU8-xOw&sig2=iBIrl1uhIsJXmPbAh4kUbw&bvm=bv.49784469,d.aWM > > You may be able to use two smooth statements to do what you want. > > John Kane > Kingston ON Canada > > > > -----Original Message----- > > From: ye...@lbl.gov > > Sent: Fri, 26 Jul 2013 12:21:23 -0700 > > To: r-help@r-project.org > > Subject: [R] add different regression lines for groups on ggplot > > > > Hey All, > > > > I need to apply different regression lines to different group on my > > ggplot, > > and here is the code I use: > > > > > qplot(x=Var1,y=Var2,data=df,color=SiteID,group=SiteID)+geom_point()+geom_smooth(method='lm',formula=log(y)~I(1/x),se=FALSE,size=2) > > > > However the regression for different groups is as below: > > > > AL1/AL2: log(y)~I(1/x) > > AL3: log(y)~log(x) > > > > How can I apply each regression equation on the same ggplot? > > > > Also I have an issue that if I use the code above, the regression lines > > are > > not overlapped on top of my data points. > > > > Thanks for your help! > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > ____________________________________________________________ > TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if5 > Capture screenshots, upload images, edit and send them to your friends > through IMs, post on Twitter®, Facebook®, MySpace, LinkedIn® FAST! > > > [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.