[R] Title with substitute and paste

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 2 22:19:42 CEST 2004


On Mon, 2 Aug 2004, Wolfgang Viechtbauer wrote:

> Hello All,
> 
> I am generating some plots where the title is generated with substitute
> and paste. An example:
> 
> nval <- 20
> plot(0,0)
> title(substitute(paste("n = ", n), list(n = nval)))
> 
> But when compared to:
> 
> plot(0,0)
> title("n = 20")
> 
> the title in the first plot looks slightly different (it is not in
> bold). How can I get the two titles to look exactly the same?

The first is an expression, the second a character string so they are 
intentionally different.  Use the same type of object to get the same 
result.

> Also, how can I generate the following plot:
> 
> plot(0,0)
> title("Test\n n = 20")
> 
> with substitute and paste? I tried:
> 
> nval <- 20
> plot(0,0)
> title(substitute(paste("Test\n", "n = ", n), list(n = nval)))
> 
> but that doesn't produce the same result.

You want to be using something like

title(paste("Test\n n =", nval))

that is using a character string and not an expression.

-- 
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