2 December, 2009
Superscripts and subscripts are often needed for axis labels and labeling of points, such as in ordination plots. Although chemical formulas are often written without subscripts (e.g., Fe203), plots will look more polished and professional if superscripts and subscripts are used. If a group of characters is followed by a final superscript or subscript (e.g., CO2, but not H2O), the superscript or subscript can be added with the expression() function, using square brackets to enclose the subscript or a carat (^) to indicate a superscript.
x <- rnorm(50)
y <- rnorm(50)
plot(x, y, xlab=expression(H), ylab=expression(R^4))
For more complicated text that contains embedded subscripts or superscripts (e.g., H2O) or multiple subscripts or superscripts (e.g., Fe2O3), the various parts of the text string will need to be joined with the paste() function.
plot(x, y, xlab=expression(paste(H, O)), ylab=expression(paste(Fe, O)))
The paste() function can accept more than two items as parameters; just separate the text strings by commas.
plot(x, y, xlab=expression(paste(Al, Si, O, (OH))))