Combining superscripts, subscripts and other symbols in axis labels

Here was a tricky questions just sent to me:

I’m trying to get  δ44/42Ca915a (‰) to look like δ44/42Ca915a (‰). I only need at this time to do the ylab. I tried using the code below from the blog.

I have tried plotting it in

boxplot(Ensisheim, ylim=c(-1.0,-0.4), col=”red”, ylab=expression(paste(delta^{44/42}, “Ca (\u2030)”))

and as just

 plot(x, y, ylab=expression(paste(delta^{44/42}, “Ca (‰)”))).

Solution

It took a bit of trial and error, but I was able to work a solution thanks to posts at stackoverflow (here and here)

x <- seq(1:10)
par(mar=c(5,6,5,5))
boxplot(x, ylab=expression(paste(delta^”44/42″, “Ca” [“915a”], ” (‰)”)))
Remember you can substitute \u2030 for ‰.

What’s happening?

expression(paste(delta^”44/42″, “Ca” [“915a”], ” (‰)”))
The superscript command ^ and subscript command [] don’t have to be followed by a comma, but if you want to call them as commands, rather the print them as characters, you have to take them out of the quotation marks, so we have “Ca” [“915a”]rather than “Ca[915a]”. If you want to join up multiple superscript/subscript/special character commands within the expression(paste()) environment, after your superscript command is over, you need a comma before you can ask it to print “Ca”, and similarly after your subscript command is over you need a comma before you can ask  it to print  ” (‰)”.

 

A special note on margins

You noticed the code  par(mar=c(5,6,5,5))I called above before I plotted my figure. This asks R to make the lefthand margin larger than the others. When using superscripts on the y-axis, I’ve found the top edge of the superscript character can sometimes  get cut off when you save the pdf from R. Just in case, make extra room in the margins!