0

I am trying to write the following label on the X-axis: "N2O emissions from the soil 0-0.3 m layer (kg/ha/yr)". I need the '2' to be a subscript and 'soil 0-0.3 m layer (kg/ha/yr)' to be on the second line of the label. I have read different posts on subscripts but it seems that the '/n' in my label is creating a confusion for the function expression and the 'N' ends up being located at the second line of the label.

 # sample data
 d <- data.frame(x=gl(2,50), y=rnorm(100))

 # the graph
 p <- ggplot(d, aes(x, y)) + 
      stat_summary(fun.data = f, geom="boxplot")
 p <- p + labs(list(title = "", x = "", y = expression("N"[2]*"O emissions from the\nsoil 0-0.3 m layer (kg/ha/yr)")))
 p

The figure with its incorrect legend:

Cecile
  • 527
  • 5
  • 22
  • 2
    That [linked duplicate](http://stackoverflow.com/questions/13223846/ggplot2-two-line-label-with-expression) should solve your problem; use `atop` rather than a newline. e.g. `y = expression(atop(paste(N[2], "O emissions from the"), "soil 0-0.3 m layer (kg/ha/yr)"))` – David Robinson Nov 19 '15 at 03:00
  • Fantastic, Thank you David! The only problem now is that I can't find out how the make it bold: I have tried theme(axis.text.y=element_text(face='bold')) but unsuccessfull with atop. Can you help me on that? – Cecile Nov 19 '15 at 06:04
  • First, you meant to do `axis.title.y`, not `axis.text.y` (the latter affects the axis ticks), though that doesn't solve this problem. Second, [see here](http://stackoverflow.com/questions/8281897/ggplot2-font-style-in-label-expression): surround the `atop` expression with `bold`: `expression(bold(atop(paste(N[2], "O emissions from the"), "soil 0-0.3 m layer (kg/ha/yr)")))` – David Robinson Nov 19 '15 at 13:37
  • @DavidRobinson, Thank you for your help and sorry for the duplicate! – Cecile Nov 20 '15 at 22:35

0 Answers0