Re: [R] add non-linear line

From: Duncan Murdoch <>
Date: Wed 17 Jan 2007 - 17:31:57 GMT

On 1/17/2007 12:24 PM, Duncan Murdoch wrote:

> On 1/17/2007 10:42 AM, Matt Sakals wrote:

>> I am trying to plot a non-linear trend line along with my data. I am
>> sure the solution is simple; any help greatly appreciated.
>> Recent and historic attempts:
>> fit = nls((sd~a+b*exp(-c/time)+d*geology), start=list(a=1, b=1, c=10,
>> d=-1), model=TRUE)
>> plot(time, sd, col=3, main = "Regression", sub=formula(fit))
>> lines(time, fitted.values(fit), lwd=2)
>> #tt = seq(from=0, to=200, by=10)
>> #lines(time, predict(fit, time=tt))
>> #lines(time, predict(fit))
> Your model has two independent variables, time and geology.  You won't 
> get a simple trend line unless the value of geology is kept fixed.  You 
> could do that with something like this code:
> lines(time, predict(fit, newdata=data.frame(time=time, geology=0)))

One other suggestion: in the new data, make sure your "time" variable is sorted into increasing order, or the lines will be a mess.

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu Jan 18 04:36:45 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 17 Jan 2007 - 18:30:23 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.