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? 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. Thanks in advance for any suggestions! -- Wolfgang Viechtbauer Department of Psychology University of Illinois, Urbana-Champaign
Try, wrapping your substitutes()'s with an eval(), as in title(eval(substitute(paste("n = ", n), list(n = nval)))) -roger 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? > > 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. > > Thanks in advance for any suggestions! >
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
Interesting ... I believe that the problem is when you use the substitute construction, you produce an expression object that is interpreted and rendered using the fonts via the plotmath facility (?plotmath). When you just use paste, the title is character and gets rendered via the defaults of title. You can make them the same by making them both character strings, e.g., vis> nval <- 20 > plot(0,0) > title(paste("n = ", nval))for example. Or you could wrap the text version in expression() to use plotmath fonts. Cheers, Bert Bert Gunter Non-Clinical Biostatistics Genentech MS: 240B Phone: 650-467-7374 "The business of the statistician is to catalyze the scientific learning process." -- George E.P. Box
Seemingly Similar Threads
- Use of MathJax (or something similar) in .Rd files
- Use of MathJax (or something similar) in .Rd files
- Compiling R-devel - missing some expected features (zlib, bzlib, lzma, PCRE)
- Finding Missing Data Patterns
- Use of MathJax (or something similar) in .Rd files