[R] Variable value in expression (plotmath)

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Sep 12 17:53:04 CEST 2000


"Dirk F. Raetzel" <raetzel at Mathematik.Uni-Marburg.de> writes:

> Hello,
> 
> I have a problem with the plotmath facility and haven't found any solution
> in the FAQ and Online-Help.
> 
> I am trying to incorporate the value of a variable in an expression for an
> axis with plotmath.
> 
> Considering having
> 
> > gamma <- 10
> 
> I'd like to have a plot with
> 
> > plot( .... , xlab=expression(gamma==10))
> 
> but depending on the true value of the variable.
> 
> How can I achieve this? I tried some combinations of paste(),
> as.expression(), c() and some other stuff, but didn't succeed.

FAQ 7.16 How can I substitute into a plot label?

Often, it is desired to use the value of an R object in a plot label,
e.g., a title. This is easily accomplished using paste() if the label
is a simple character string, but not always obvious in case the label
is an expression (for refined mathematical annotation). In such a
case, either use parse() on your pasted character string or use
substitute() on an expression. For example, if ahat is an estimator of
your parameter a of interest, use

title(substitute(hat(a) == ahat, list(ahat = ahat)))

(note that it is == and not =). There are more worked examples in the
mailing list achives.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list