[R] numerical values in expressions

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Mar 20 08:37:52 CET 2006


Stephan Lorenzen wrote:
> Hi there, 
> 
> I fitted a curve to some data and want to write the equation of the
> fitted curve in the figure legend. If I write 
> 
> paste(format(fitZ$estimate[1], digits=2), "e^", format(fitZ$estimate[2],
> digits=2), "x +", format(fitZ$estimate[3], digits=2))
> 
> i get unformatted output, writing "e^-0.0039x" instead of superposing
> the exponent. I tried several variants of "expression", but finally only
> the explicit one 
> 
> expression(0.061 * e^"-0.0039x" + 0.010)
> 
> where I have to provide the values myself worked. Is there any way to
> use the "expression" function to reference actual values of variables
> instead of just outputting their names?


See the article "R Help Desk: Automation of Mathematical Annotation in 
Plots" in R News 2(3).

Example for this case:

  a <- format(fitZ$estimate[1], digits=2)
  b <- format(fitZ$estimate[2], digits=2)
  d <- format(fitZ$estimate[3], digits=2)

  plot(1:10, main = substitute(a * e^b * x + d,
                               list(a=a, b=b, d=d)))



Uwe Ligges

> Thanks,
> 
> Stephan
> 
> ______________________________________________
> R-help at 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




More information about the R-help mailing list