[R] Label using equivalent of \mathbb{R}

Paul Murrell p.murrell at auckland.ac.nz
Fri Aug 27 02:05:26 CEST 2004


Deepayan Sarkar wrote:
> On Thursday 26 August 2004 11:41, Martin Maechler wrote:
>>>>>>>"Simon" == Simon Cullen <cullens at tcd.ie>
>>>>>>>    on Thu, 26 Aug 2004 15:30:06 +0100 writes:
>>    Simon> On Thu, 26 Aug 2004 15:24:33 +0200, Trenkler,
>>    Simon> Dietrich <dtrenkler at nts6.oec.uni-osnabrueck.de>
>>    Simon> wrote:
>>    >> [Dietrich Trenkler]
>>    >>
>>    >>
>>    >> plot(rnorm(10),xlab=expression(bold(x)),ylab=expression(bold(y)))
>>    Simon> Not quite what I am looking for, I'm afraid. \mathbb
>>    Simon> gives "blackboard" fonts - the capitals with two
>>    Simon> vertical parallel lines in them that are used for the
>>    Simon> Reals, Complex numbers etc.
>>yes (and Dieter confused \mathbb{} with \mathbf{}).
>>R's builtin plotmath utilities can't do this directly.
>>A workaround would be similar to what we used to do in LaTeX 2.09
>>times (before \mathbb{} was standardly available):
>>      { "I", <negative space>, "R" }
>>Whereas with (La)TeX, a macro definition was relatively
>>easy for the above, it might be a bit harder / more ugly with
>>current R builtins, for one because I don't think ``plotmath''
>>has a concept of <negative space>.
>>1)  A really ugly hack would work with  text() -- not quite useful
>>   if you'd like these in 'xlab' etc.
>>2)  A potentially much nicer scheme might be to use  "grid" instead of
>>   oldstyle  "graphics" :  There one could construct a  "grob"
>>   (graphical object) for the '|R' symbol that one could should be
>>   pass to other functions -- though it may need some tweaking
>>   before a function like (pkg lattice's) xyplot() would accept
>>   a grob for xlab [instead of only a character or expression].
> Interesting thought. Should be almost trivial to implement.
> Currently, legends (sort of generalized key-s in the Trellis context) can be 
> grobs, e.g.
> bbR <- textGrob(c("I", "R"), x = 0.7 * c(-1, 1), 
>                 default.units = "mm", 
>                 vp = viewport(h=0, w=0))
> xyplot(1 ~ 1, xlab = NULL, legend = list(bottom = list(fun = bbR)))

Cool :)  An alternative hack would be to treat this as an annotation of 
the lattice panel.  For example ...

xyplot(1 ~ 1, xlab = "") # NOTE "" not NULL
pushViewport(viewport(clip="off")) # to be able to draw outside panel
grid.text(c("I", "R"), y=unit(-2, "lines"),
           x=unit(0.5, "npc") - 0.5*stringWidth(c("I", "")),

...  (using stringWidth makes the hack scale with font size).

In this case though, I think the ideal solution would be just to use a 
font that has the desired character.  On Windows this should be doable 
via the file RHOME\etc\Rdevga and something like mtext(..., font=<some 
large number>) [assuming that the appropriate font can be found and 

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

More information about the R-help mailing list