[R] Using bold font with bquote

Paul Murrell p.murrell at auckland.ac.nz
Wed Aug 12 23:40:49 CEST 2009


Hi

Jonathan R. Blaufuss wrote:
> Scott, Your suggestion works great for changing the numbers to bold
> font, but is it possible to change the sigma symbol and the equals
> sign to bold font as well? I've poked around ?plotmath and am I right
> in saying that there is a different method for controlling symbol
> fonts?


R graphics only recognizes a plain symbol font (it has this weird idea 
that a symbol font is a font face like bold or italic).

For your particular example, because it is not a complex math formula, 
you might be able to do a workaround by constructing a simple string and 
specifying the symbol that you want using Unicode.  Depending on what 
system and fonts you have, the following might work ...

	text(25000,0.00004,
	     paste("\u03c2 = ",
                    format(round(sd(Data),digits=3),big.mark=",")),
	     font=2, col="blue")


Paul


> Thank you for your help,
> 
> Jonathan
> 
> ----- Original Message ----- From: "Scott Sherrill-Mix"
> <shescott at mail.med.upenn.edu> To: "Jonathan R. Blaufuss"
> <blaufusj at carleton.edu> Cc: r-help at r-project.org Sent: Wednesday,
> August 12, 2009 12:43:12 PM GMT -06:00 US/Canada Central Subject: Re:
> [R] Using bold font with bquote
> 
>> From ?plotmath, it looks like when using expressions you set the
>> font
> inside the expression (e.g. bold(x)). It looks you tried this already
>  but I wonder if there was something tiny out of place since the 
> following works for me:
> 
> text(25000,0.00003,bquote(bold(sigma==.(mySigma)),list('mySigma'=format(round(sd(Data),digits=3),big.mark=","))),
>  col='blue')
> 
> Scott
> 
> Scott Sherrill-Mix Department of Microbiology University of
> Pennsylvania 402B Johnson Pavilion 3610 Hamilton Walk Philadelphia,
> PA  19104-6076
> 
> 
> 
> On Wed, Aug 12, 2009 at 12:36 PM, Jonathan R. 
> Blaufuss<blaufusj at carleton.edu> wrote:
>> I'm trying to annotate a density plot and I'm using bquote to paste
>> the sigma symbol next to the numeric text of the standard deviation
>> calculation that I am performing. I have been able to successfully
>> turn the sigma symbol and numeric output the color blue, but when I
>> try to change the font of the text to bold, R doesn't seem to
>> recognize the "font=" command in the same way here as it does with
>> "col=". (My code is below)
>> 
>> set.seed(1) Data=rnorm(100,sd=10000) plot(density(Data)) 
>> text(25000,0.00003, bquote(sigma==.(mySigma), 
>> list('mySigma'=format(round(sd(Data),digits=3),big.mark=","))), 
>> col="blue")
>> 
>> After searching the help files I've tried using the expression
>> command with "bold()" as well as inserting "font=2" after the color
>> command. However, I can't seem to get it to work.
>> 
>> Can someone please point me to a resource that will help me figure
>> this out?
>> 
>> Thank You,
>> 
>> Jonathan
>> 
>> ______________________________________________ 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.
>> 
> 
> ______________________________________________ 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.

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list