Skip to content
Back to formatted view

Raw Message

Message-ID: <418A35C8.4040602@ucl.ac.uk>
Date: 2004-11-04T13:59:36Z
From: Gavin Simpson
Subject: sub- and superscript in plot labels
In-Reply-To: <Pine.LNX.4.44.0411041237010.11570-100000@gannet.stats>

Prof Brian Ripley wrote:
> On Thu, 4 Nov 2004, Gavin Simpson wrote:
> 
> 
>>Dear List,
>>
>>I need to add a subscript and a superscript to some of the ions in the 
>>labels on some plots.
>>
>>I have got to here but now I'm stuck:
>>
>>plot(1:10, xlab = expression(paste("nm SO"[4], " ", mu, "eq cm"^{-2}, " 
>>yr"^{-1})))
>>
>>Which gives almost  what I require. No matter what I tried, however, I 
>>could not get bot a sub script *and* a superscript attached to the SO in 
>>the label.
>>
>>In LaTeX I would just do $SO_4^{2-}$ but taking that to R produces a 
>>syntax error:
>>
>>plot(1:10, xlab = expression(paste("nm SO"[4]^{2-}, " ", mu, "eq 
>>cm"^{-2}, " yr"^{-1})))
> 
> 
> The problem is 2-.  That's not an R expression.  Using "2-" might give
> what you want, but it will use a hyphen rather than a minus. Otherwise
> 
> plot(1:10, xlab = expression(paste("nm SO"[4]^{2-phantom()})))
> 
> will give a minus.
> 

Many thanks to Brian Ripley and Bendix Carstensen for your replies.

Both of the above options produce what I was after. One quick follow-up 
question regarding the use of phantom(). Looking at ?plotmath phantom 
leaves space for a character passed as an argument to phantom(), but 
does not plot it.

In the example above we are leaving space for "nothing". I don't 
understand why this is a valid R expression. I guess phantom() is 
returning something that makes 2-<returned_val> a valid expression, but 
I couldn't find the help for ?phantom so I couldn't check on this in the 
documentation.

Also as an aside, phantom() appears, visually, to be a function, but it 
is not visible to the user as a function. i.e. typing phantom at the 
prompt yields: Error: Object "phantom" not found. getAnywhere(phantom) 
yields nothing either. What is phantom() in R parlance?

All the best,

Gavin

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                     [T] +44 (0)20 7679 5522
ENSIS Research Fellow             [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC                 [E] gavin.simpson at ucl.ac.uk
UCL Department of Geography       [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way                    [W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%