print formula on plot

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

print formula on plot

Thomas Steiner
I estimate some parameters and I want to print them (pretty) on my plot:

# somehow estimated parameters
z<-c(1.543523e+00, 1.23453e+00, 3.454000e+00)

x<-seq(-1,1,length=100)
plot(x,z[3]*x^2+z[2]*x+z[3],type="l", main="My nice plot of the
estimated function")
zs<-format(z,digits=4,scientific=FALSE,trim=TRUE)

text(-0.9,7,expression(1.54*x^2))                   # is what I want,
but DYNAMIC
text(-0.9,6,expression(paste(zf[1],x^3)))         # not really
text(-0.9,5,expression(paste(toSting(zf[1]),x^3)))  # not really
#using z (double) instead of zf (string) does not help.

So my question is:
How do I evaluate zf[1] from the variable to it's (String) value? Here
it is used within an expression: this makes all the trouble.

Thanks for help, I tried 2 hrs now...
Thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: print formula on plot

Thomas Steiner
I found it immediately after posting :(

substitute is my friend:

text(0.5,5,substitute(f[Sv] ==k*x^2, list(k=zf[1])))

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: print formula on plot

Robert Baer
In reply to this post by Thomas Steiner
Only put the expression inside the expression?

> plot(x,z[3]*x^2+z[2]*x+z[3],type="l", main="My nice plot")
> text(-0.9,5,paste(zs[1],' ',expression(x^3)))  # should work

____________________________
Robert W. Baer, Ph.D.
Associate Professor
Department of Physiology
A. T. Still University of Health Science
800 W. Jefferson St.
Kirksville, MO 63501-1497 USA
----- Original Message -----
From: "Thomas Steiner" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, February 08, 2006 7:47 AM
Subject: [R] print formula on plot


> I estimate some parameters and I want to print them (pretty) on my plot:
>
> # somehow estimated parameters
> z<-c(1.543523e+00, 1.23453e+00, 3.454000e+00)
>
> x<-seq(-1,1,length=100)
> plot(x,z[3]*x^2+z[2]*x+z[3],type="l", main="My nice plot of the
> estimated function")
> zs<-format(z,digits=4,scientific=FALSE,trim=TRUE)
>
> text(-0.9,7,expression(1.54*x^2))                   # is what I want,
> but DYNAMIC
> text(-0.9,6,expression(paste(zf[1],x^3)))         # not really
> text(-0.9,5,expression(paste(toSting(zf[1]),x^3)))  # not really
> #using z (double) instead of zf (string) does not help.
>
> So my question is:
> How do I evaluate zf[1] from the variable to it's (String) value? Here
> it is used within an expression: this makes all the trouble.
>
> Thanks for help, I tried 2 hrs now...
> Thomas
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: print formula on plot

Gabor Grothendieck
In reply to this post by Thomas Steiner
Also see ?bquote

On 2/8/06, Thomas Steiner <[hidden email]> wrote:

> I found it immediately after posting :(
>
> substitute is my friend:
>
> text(0.5,5,substitute(f[Sv] ==k*x^2, list(k=zf[1])))
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: print formula on plot

Thomas Steiner
In reply to this post by Robert Baer
> > text(-0.9,5,paste(zs[1],' ',expression(x^3)))  # should work

this produces a 2x^3 and not 2x"superscript"(3) - just execute it and
you see what I mean. anyway, substitute helps and bquote could shorten
it a bit.
Anywa thanks!
Thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html