0

I only want to write Fe2+ with "2+" superscripted.

This works ("+2" is superscripted, but the sequence is wrong):

df <-data.frame(a=seq(1,20),b=seq(1,20))
ggplot(df, aes(x = a, y = b)) + geom_point() +
  xlab(expression(Fe^{+2} ~ (mu ~ M)))

This doesn't:

ggplot(df, aes(x = a, y = b)) + geom_point() +
  xlab(expression(Fe^{2+} ~ (mu ~ M)))

apparently, the "+" operator after "2" in {2+} needs special treatment. Any help is appreciated.

Alernatively, i would be delighted if someone may solve the same problem for the following expression:

ggplot(df, aes(x = a, y = b)) + geom_point() +
xlab(bquote(Fe^2+~' '~'('*mu~'M)'))
nouse
  • 3,315
  • 2
  • 29
  • 56
  • 1
    Related: [Minus as an exponent in plotmath (in ggplot2 legend)](http://stackoverflow.com/questions/13636096/minus-as-an-exponent-in-plotmath-in-ggplot2-legend). Thus, `xlab(expression(Fe^{2+phantom()} ~ (mu ~ M)))` works. – Henrik Jan 09 '17 at 16:56

1 Answers1

1

Here is a quick workaround. It looks like the + is getting parsed at some point, and is throwing an error because there is no right-hand side. So, adding an empty argument does the trick:

ggplot(df, aes(x = a, y = b)) + geom_point() +
  xlab(expression(Fe^{2+''}~(mu ~ M)))

The plus sign still renders in the label, though, so I am not sure where the parsing is happening.

The same basic approach works for the bquote version as well:

ggplot(df, aes(x = a, y = b)) + geom_point() +
  xlab(bquote(Fe^{2+''}~' '~'('*mu~'M)'))
Mark Peterson
  • 9,370
  • 2
  • 25
  • 48