Dear all, I am trying to plot some text in bold face which works fine: plot(0:1,0:1,type="n") text(x=0.5, y=0.5, labels=expression(bold("the-actual-string"))) Now when I try to do the following, the displayed text reads thestring: thestring <- "the-actual-string" plot(0:1,0:1,type="n") text(x=0.5, y=0.5, labels=expression(bold(thestring))) Can someone tell me what I am doing wrong? I assume it is rather simple but I am stuck somehow. Thanks in advance, Roland P.S. I tried it using ("ancient") R 2.7.0 on Windows32 and version 2.8.1 on GNU/Linux (Ubuntu 8.10). ---------- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance.
On Mon, 2 Mar 2009, Rau, Roland wrote:> Dear all, > > I am trying to plot some text in bold face which works fine: > > plot(0:1,0:1,type="n") > text(x=0.5, y=0.5, labels=expression(bold("the-actual-string"))) > > Now when I try to do the following, the displayed text reads thestring: > > thestring <- "the-actual-string" > plot(0:1,0:1,type="n") > text(x=0.5, y=0.5, labels=expression(bold(thestring)))See ?substitute (or its wrapper bquote) E.g.> lab <- substitute(bold(thestring), list(thestring=thestring)) > text(x=0.5, y=0.5, labels=lab)But, why are you setting plain text as an expression? The better way to do this is thestring <- "the-actual-string" plot(0:1,0:1,type="n") text(x=0.5, y=0.5, labels=thestring, font=2) See ?par (and ?text). There are subtle differences (e.g. how the baslines are aligned), and using plotmath when you do not need it will get you encountering those differences.> Can someone tell me what I am doing wrong? I assume it is rather simple > but I am stuck somehow. > > Thanks in advance, > Roland > > P.S. I tried it using ("ancient") R 2.7.0 on Windows32 and version 2.8.1 > on GNU/Linux (Ubuntu 8.10).-- 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
Dear Prof. Ripley,> -----Original Message----- > From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk] > Sent: Monday, March 02, 2009 3:05 PM > To: Rau, Roland > Cc: r-help at r-project.org > Subject: Re: [R] Bold Face in Plot > > thestring <- "the-actual-string" > plot(0:1,0:1,type="n") > text(x=0.5, y=0.5, labels=thestring, font=2) >thank you very much. Using the font argument, I accomplished what I wanted to do. Thanks again, Roland ---------- This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance.
Rau, Roland <Rau <at> demogr.mpg.de> writes:> I am trying to plot some text in bold face which works fine: > > plot(0:1,0:1,type="n") > text(x=0.5, y=0.5, labels=expression(bold("the-actual-string"))) > > Now when I try to do the following, the displayed text reads thestring: > > thestring <- "the-actual-string" > plot(0:1,0:1,type="n") > text(x=0.5, y=0.5, labels=expression(bold(thestring))) >"expression" can be mind twisting. For a probably more realistic example, see the following: plot(0:1,0:1,type="n") ss1 = paste("there was ",expression(Delta)) ss = substitute(paste("there was ",expression(Delta))) text(x=0.3, y=0.3, labels=ss1) text(x=0.4, y=0.4, labels=ss) Dieter
Here is one way: thestring <- "the-actual-string" plot(0:1,0:1,type="n") text(x=0.5, y=0.5, labels=bquote(bold(.(thestring)))) There is an example in the plotmath help page that shows using bquote (but that page has so much information that I did not find it on my first scan through even knowing what to look for). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Rau, Roland > Sent: Monday, March 02, 2009 6:46 AM > To: r-help at r-project.org > Subject: [R] Bold Face in Plot > > Dear all, > > I am trying to plot some text in bold face which works fine: > > plot(0:1,0:1,type="n") > text(x=0.5, y=0.5, labels=expression(bold("the-actual-string"))) > > Now when I try to do the following, the displayed text reads thestring: > > thestring <- "the-actual-string" > plot(0:1,0:1,type="n") > text(x=0.5, y=0.5, labels=expression(bold(thestring))) > > Can someone tell me what I am doing wrong? I assume it is rather simple > but I am stuck somehow. > > Thanks in advance, > Roland > > P.S. I tried it using ("ancient") R 2.7.0 on Windows32 and version > 2.8.1 > on GNU/Linux (Ubuntu 8.10). > > ---------- > This mail has been sent through the MPI for Demographic Research. > Should you receive a mail that is apparently from a MPI user without > this text displayed, then the address has most likely been faked. If > you are uncertain about the validity of this message, please check the > mail header or ask your system administrator for assistance. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.