[R] mathematical expressions in main
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Wed May 5 18:02:35 CEST 1999
Peter Baker <p.baker at qut.edu.au> writes:
> Hi
>
> I've tried and tried and I presume it is very simple but .....
>
> I want some varying titles for plots using greek symbols
> eg using an expression like
>
> for (true in c(0:5))
> plot(...,main = expression(paste(phi," = ",true,sigma)),...)
>
> where phi and sigma are greek symbols. Instead of \phi=2\sigma I get
> \phi=true\sigma as true is taken as a text string - not a variable.
>
> Any help much appreciated
Problem is not in plot but in the fact that expression takes
everything inside literally:
> expression(paste(phi," = ",true,sigma))
expression(paste(phi, " = ", true, sigma))
Try creative uses of substitute:
> substitute(expression(paste(phi, " = ", true, sigma)),list(true=5))
expression(paste(phi, " = ", 5, sigma))
and then
> plot(0,0,main=substitute(expression(paste(phi, " = ", true,
+ sigma)),list(true=5)))
...which doesn't quite work, because the result is an object of mode
"call" (namely to the primitive function "expression"), not the result
of such a call (which is of mode "expression", although it prints
identically -- yes, this is confusing!).
What does work is either to evaluate the call, yielding an object of
mode "expression":
> plot(0,0,main=eval(substitute(expression(paste(phi, " = ", true,
+ sigma)),list(true=5))))
...or to use the fact that an object of mode "call" is also allowed for
math graphics and dump the expression bit:
> plot(0,0,main=substitute(paste(phi, " = ", true, sigma),list(true=5)))
--
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