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.