[R] variable values in plotmath expressions

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Sep 3 09:36:47 CEST 2004


?substitute, as in

plot(1, 1,
     main = expression(main[x1]),
     xlab = substitute(paste(t, xlab[x2]), list(t=t)),
     sub = parse(text = paste("sub[", x, "]"))
     )

[Why do you think ( needs a space but = does not?  There is a canonical
way to display R code: see `Writing R Extensions' -- please use it.  
Communication is about making life easy for your readers.]

On Fri, 3 Sep 2004, Wolfram Fischer wrote:

> I tried:
> 
>     t <- "sample text"
>     x <- 333
> 
>     plot( 1, 1
>         , main=expression( main[x1] )
>         , xlab=expression( paste( t, xlab[x2] ) )
>         , sub=parse( text = paste( "sub[", x, "]" ) )
>         )
> 
> The displayed labels for ``main'' and ``sub'' are as expected.
> But ``xlab'' shows only "t" not "sample text".
> How can I insert the string on which ``t'' points?
> 
> I tried e.g.:
>     , ylab=parse( text = paste( t, "ylab[", x, "]" ) )
> but I received an error (as suspected).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list