[R] Displaying R, N, Z-symbols with expression

Paul Murrell paul at stat.auckland.ac.nz
Thu Nov 22 09:02:18 CET 2007


Hi


David Winsemius wrote:
> "C.J.Albers" <C.J.Albers at open.ac.uk> wrote in
> news:2DB62B9891E94943806FE03F1C50DC99BB96B7 at SHERWOOD.open.ac.uk: 
> 
>> Hi all,
>>
>> (Apologies if this has been asked before; I tried to search for it in
>> the archives, but searching for terms like 'N' yields too many hits) 
>>
>> Is it possible to display symbols like 'R' (the set of real numbers,
>> so with an additional vertical line on the left) in plots using
>> expression/plotmath? Getting bounced by the LISTSERV so trying Gmane:
> 
> 
> Install the Hershey vector fonts and then use something like:
> plot(0,0)
> text(0.25.0.25, "\\Re", vfont = c("serif symbol", "bold italic"), cex = 
> 1.5)
> 
> It's more "Gothic" than what you described, but it may be an acceptable 
> substitute.


I think that symbol is referred to as "R fraktur";  you can also get 
that via the symbol font, e.g., ...

library(grid)
grid.text(expression(symbol("\302")))

If you want an R fraktur that looks more like a Latex one, see
http://www.stat.auckland.ac.nz/~paul/R/CM/CMR.html

If you want the so-called "bold blackboard" fonts, for some devices at 
least, you should be able to access the font from your Latex 
distribution.  For example, the following code grabs the psyb font from 
the pxfonts package and uses it with R's PDF device (the paths to the 
font .afm and .pfb files may be different on your system) ...

# Tell R where the font .afm files are
pdfFonts(pxfonts=Type1Font("pxfonts",
            paste("/usr/share/texmf-tetex/fonts/afm/public/pxfonts/",
                  rep("pxsyb.afm", 4), sep="")))

pdf("pxfonttest.pdf")
# Use the pxfont
grid.text("R", gp=gpar(fontfamily="pxfonts"))
dev.off()

# Embed the pxfont so that readers and printers will
# not substitute a different font
embedFonts("pxfonttest.pdf",
     fontpaths="/usr/share/texmf-tetex/fonts/type1/public/pxfonts/")

Paul

p.s.  There's no need to "install" the Hershey fonts;  they come as part 
of R.
-- 
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