[R] Answer found: Re: How to write a function in a graph

From: junguo liu <water21water_at_yahoo.com>
Date: Thu 20 Jul 2006 - 03:05:56 EST


Dear Thomas and Simon,    

  Thank you for your messages. I have found the best solution based on your advice. FAQ 7.13 does provide an effective way to answer my question.    

  Kind regards,
  Junguo

Thomas Lumley <tlumley@u.washington.edu> wrote:   On Tue, 18 Jul 2006, junguo liu wrote:

> Dear R-ers,
>
> 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.

This is FAQ 7.13.

-thomas

>
>
> CODE
>
> # Read data
> x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
> y <- c(6, 5, 8, 9, 11, 10, 11, 12, 15)
> data01 <- data.frame(x, y)
>
> # 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))
> #=======
>
> ## I intended to add text like y=4.33+1.07x
> ## but the above code added y=a+bx
>
>
>
> 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.
>

Thomas Lumley Assoc. Professor, Biostatistics tlumley@u.washington.edu University of Washington, Seattle

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 Thu Jul 20 03:12:14 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 Thu 20 Jul 2006 - 04:22:00 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.