0

Really struggling to get the code right for a ggplot y-axis label. Please can someone help me out before I break the computor...

This is the code for my graph:

ggplot(urea, aes(x = Time, y = Flux_N2O, fill = Chamber, colour = Chamber)) + 
  geom_point() + geom_line() + scale_y_continuous(limits = c(0,300)) +
  scale_x_datetime(date_breaks= "7 days", date_minor_breaks = "1 day") + 
  xlab("n/Date") + ylab(expression(N[2]O-N~Flux~(mug~m^{-2}~h^{-1})))

I want it to look like this N2O Flux ug m-2 h-1 where the "2" in "N2O" is sub-scripted and all the other numbers are super-scripted an mu in the Greek for micro.

I have looked at other similar questions on SO but can't figyre out what I'm doing wrong. I am getting the following error:

Error: unexpected symbol in:
"  scale_x_datetime(date_breaks= "7 days", date_minor_breaks = "1 day") + 
  xlab("n/Date") + ylab(expression(N[2]O"
Rory Shaw
  • 811
  • 2
  • 9
  • 26
  • 1
    [This post](http://stackoverflow.com/questions/15125628/putting-mathematical-symbols-and-subscripts-mixed-with-regular-letters-in-r-ggpl) and [this post](http://stackoverflow.com/questions/10156417/subscripts-in-plots-in-r) are probably useful. – bouncyball Jun 28 '16 at 12:43
  • Also, check this out: http://stackoverflow.com/questions/17334759/subscript-letters-in-ggplot-axis-label – Sumedh Jun 28 '16 at 12:45
  • 2
    something like `ylab(expression(paste(N[2], "O-N Flux(",~mu,"g", ~m^{-2}~h^{-1},")")))` – bouncyball Jun 28 '16 at 13:05
  • 1
    `ylab(expression(N[2]*O-N~Flux~(mu*g~m^{-2}~h^{-1})))` – fc9.30 Jun 28 '16 at 13:11
  • @bouncyball thanks that works, would be good to to it without `paste()` though – Rory Shaw Jun 28 '16 at 13:13
  • @fc9.30 thanks. Can you elaborate on what the * does, I dont fully understand its usage – Rory Shaw Jun 28 '16 at 13:15

0 Answers0