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}))) Strangely, I can do this: plot(1:10, xlab = expression(paste("nm SO"[4]^2, " ", mu, "eq cm"^{-2}, " yr"^{-1}))) With almost the desired effect (except I need to add two characters to the superscript). Can any one offer a solution? Many thanks 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. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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
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}))) > > Strangely, I can do this: > > plot(1:10, xlab = expression(paste("nm SO"[4]^2, " ", mu, "eq cm"^{-2}, > " yr"^{-1}))) > > With almost the desired effect (except I need to add two characters to > the superscript). > > Can any one offer a solution? > > Many thanks > > GavinWith further playing around, it would appear that you can sort of achieve what I was looking for by changing the ordering of the characters in the braces on the superscript: plot(1:10, xlab = expression(paste("nm SO"[4]^{-2}, " ", mu, "eq cm"^{-2}, " yr"^{-1}))) which works as required. Is this intentional behaviour? My original question still stands, however, is there a way to have {2-} appear as the superscript? The forgotten version info (sorry!): > version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status Patched major 2 minor 0.0 year 2004 month 10 day 25 language R Running on Fedora Core 2. Many thanks 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. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
try: plot(1:10, xlab = substitute( expression(paste("nm SO"[4]^{2-x}, " ", mu, "eq cm"^{-2}, " yr"^{-1})), list(x="") ) ) I have no understanding of why it works, formula fidgeting usually requires use of subtitute(). Btw. I started out trying: plot(1:10, xlab = substitute( expression(paste("nm SO"[4]^x, " ", mu, "eq cm"^{-2}, " yr"^{-1})), list(x="2-") ) ) but that gives a hyphen and not a minus trailing the superscript "2". Bendix Carstensen> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Gavin Simpson > Sent: Thursday, November 04, 2004 1:20 PM > To: R-help at stat.math.ethz.ch > Subject: [R] sub- and superscript in plot labels > > > 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}))) > > Strangely, I can do this: > > plot(1:10, xlab = expression(paste("nm SO"[4]^2, " ", mu, "eq > cm"^{-2}, > " yr"^{-1}))) > > With almost the desired effect (except I need to add two > characters to > the superscript). > > Can any one offer a solution? > > Many thanks > > 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. > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~ > %~%~%~%~% > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html >