# [R] How to write a function in a graph

From: junguo liu <water21water_at_yahoo.com>
Date: Wed 19 Jul 2006 - 07:23:23 EST

I conducted a regression analysis, and then intended to add the regression function (y=4.33+1.07x) in a graph. But the following code can only give me a text like y=a+bx. Who can help me out? Thank you very much in advance.

# Regression analysis

res.lm.y <- nls(y~a+b*x, start=list(a=1, b=2),data=data01)

# Obtain parameters

a<- coef(res.lm.y)["a"]
b<- coef(res.lm.y)["b"]
a
b
#a=4.33
#b=1.07

# Plot the results

def.par <- par()
par(mfrow=c(1,1),xaxs="i",yaxs="i")
plot(data01\$x,data01\$y,main="Fit",xlab="x",ylab="y")   lines(data01\$x,predict(res.lm.y))

#=======

text (6, 13, expression(y==a+b*x))
#=======

Swiss Federal Institute for Environmental Science and Technology (EAWAG) Ueberlandstrasse 133
P.O.Box 611
CH-8600 Duebendorf
Switzerland
Phone: 0041-18235012
Fax: 0041-18235375

[[alternative HTML version deleted]]

R-help@stat.math.ethz.ch 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. Received on Wed Jul 19 07:33:15 2006

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 19 Jul 2006 - 08:17:58 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.