0

I want the y axis labe in two rows; line break after evolvedI am having problem in getting the line break in y axis title. It contains suprescript and subscript and I am using following code:

 ylab(bquote("Cumulative CO" [2] * " evolved (mg CO" [2]*"-C kg"^-1* "soil)")) +
  xlab("Incubation time (days)") + 

I want line break after evolved. I have tried using \n and cannot get the desired result.

 ylab(bquote("Cumulative CO" [2] * " evolved (mg CO" [2]*"-C kg"^-1* "soil)")) +
  xlab("Incubation time (days)") 

I tried \n but I get "evolved" in the upper row and other sentence in the second row.

SS101
  • 1
  • 1
  • Welcome to StackOverflow. To help others help you, please take the tour: https://stackoverflow.com/tour and EDIT your question so that it meets the guidelines provided here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – John Polo Feb 08 '23 at 01:40
  • We don't have any of your data in order to run your code, which is seemingly incomplete anyway, and we also can't see any of your output. It's unclear what the problem is, what you want to change, or what you want to change it to – camille Feb 08 '23 at 01:43
  • I have attached the plot here. The data file is really large to upload here. I just need the code for the axis labs. I just want to arrange the units (seen in the ylab tittle) in separate rows. – SS101 Feb 08 '23 at 02:01

1 Answers1

1

You can try using the atop function:

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  ylab(expression(atop("Cumulative CO" [2] * "", paste("evolved (mg CO" [2]*"-C kg"^-1* "soil)"))))

enter image description here

Edward
  • 10,360
  • 2
  • 11
  • 26