6

How do I superscript the units this axis title. The "" represent the parts that I need to be superscripted: Photosynthetically available radiation (µE m"-2"d"-1").

I have used the formula and having no luck so far:

plot(PAR~SST,data=brazilw, pch=15,col="red", main ="Fig. 1. Relationship between photosynthically available radiation\n and sea surface temperature",
ylab=expression("Photosynthetically available radiation (µE m"^-2~d^-1))
Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
user3170629
  • 489
  • 3
  • 12
  • 21
  • possible duplicate of [Use superscripts in R axis labels](http://stackoverflow.com/questions/10628547/use-superscripts-in-r-axis-labels) – Stedy Jan 07 '14 at 20:06
  • I cannot reproduce the problem: `plot(1, ylab = expression("Photosynthetically available radiation (µE m"^-2~d^-1))`. – Sven Hohenstein Jan 07 '14 at 20:14

2 Answers2

10

Whilst I don't see a real problem in this particular instance, I can see if being an issue with other labels. I tend to group the elements of the super/subscript in braces { }, LaTeX stylee.

Here is an example:

plot(1:10,
     ylab = expression("Photosynthetically available radiation" ~ 
                         (µE ~ m^{-2} ~ d^{-1})
                       )
     )

There are gotchas with your version and the one above; the bit in the braces also needs to be a valid expression, hence

plot(1:10,
     ylab = expression("Photosynthetically available radiation" ~ (µE ~ 
                         m^{2-} ~ d^{1-})))

fails with an error. (I sometimes need those forms for writing down formulae for ions for example). To solve this issue you really do need the braces { } and you need something to come after the - operator. This latter feature is handled by phantom(), which leaves space in the expression for its argument, but as we won;t specify one, it is just a placeholder for nothing that can go on the right hand side of -:

plot(1:10,
     ylab = expression("Photosynthetically available radiation" ~ (µE ~ 
                         m^{2-phantom()} ~ d^{1-phantom()})))

phantom() is also quite useful for placing a sub/superscript before a string, like you would with isotope notation

plot(1:10, ylab = expression(phantom()^{210} * Pb))
Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • This is great so far, but I need a final bracket to close off the units i.e. (µE m-2 d-1). I have tried adding this in but it is not working, how would you add the last closing bracket? – user3170629 Jan 07 '14 at 20:36
  • 2
    @user3170629 Sorry I forgot that didn't I. Will edit the above; the way I do it is personal preference, you could add it as `* ")"` as the last part of the expression. I prefer not to quote, so the solution I'll add above is to take the entire units specification in the parentheses out of the initial string, then you treat `(` and `)` like brackets in an equation. – Gavin Simpson Jan 07 '14 at 20:57
2

Two problems I see: There is not sufficient space for the superscripts on the margin and there is no closing right-paren. It's easy enough to add the closing paren with:

ylab=expression("Photosynthetically available radiation (µE m"^-2~d^-1*")"))

(You do need to quote the paren because it is "active" or "special" in expressions. Or you could use the plotmath group-function. The margin is accessible with the par command or you could use the title command to specify a ylab that is closer to the plot:

plot(1,1, ylab="")
title(ylab=expression("Photosynthetically available radiation (µE m"^-2~d^-1*")"),
      line=2)
IRTFM
  • 258,963
  • 21
  • 364
  • 487