[R] sub- and superscript in plot labels
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Nov 4 13:42:23 CET 2004
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.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list