1

I am trying to add chemical notation and units to my y-axis label, but for some reason when I add a superscript minus sign, it throws my bracketed units into superscript too.... should I be putting the minus sign into some brackets? Any help would be appreciated.

Just to clarify it is the Nitrate symbol - so the 3 is in subscript and the minus sign is superscript, which I managed to do, I just cannot get it out of superscript.

Here is some data:

dat<-as.data.frame(matrix(runif(100), 2,10))
names(dat) <- LETTERS[1:2]

library(ggplot2)
P1 <- ggplot(dat, aes(A,B)) +
geom_point()

P1 <- P1 + labs(y=expression(rho*"NO"[3]^- ~(µmol ~L^-1 ~d^-1))) 
Lmm
  • 403
  • 1
  • 6
  • 24

2 Answers2

2

It looks like the minus is looking for a notation. If you manually pass it a blank, it'll work.

library(ggplot2)
ggplot(dat, aes(A,B)) +
  geom_point() + labs(y=expression(rho*"NO"[3]^-"" ~(µmol~L^-1 ~d^-1)))
Anonymous coward
  • 2,061
  • 1
  • 16
  • 29
2

As there is no number following the - symbol you need quote it and put it in curly brackets

P1 + labs(y=expression(rho*"NO"[3]^{"-"} ~(µmol ~L^-1 ~d^-1)))
GordonShumway
  • 1,980
  • 13
  • 19