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: