I have a plot with a long label containing an expression and I want to split it on two lines.
Adding a "\n" inside the expression the result is not as expected.
ylabel <- expression("A very long label with text and \n
expression"*(alpha+beta) [ij]*" A very long label with text and expression")
curve(x^3 - 3*x, -2, 2, xlab=xlabel)
Any help would be appreciated. Thanks
Here is another solution, relying on atop as did @AndresT in his edit.
Note that we cannot use control character like \n in an expression, which explains why using something like expression(paste("...\n", alpha[i], "....")) would not produce the desired output.
xlabel <- expression(atop("A very long label with text and expression",
paste((alpha+beta)[ij], " A very long label ...")))
curve(x^3 - 3*x, -2, 2, sub=xlabel, xlab="")
Note that I used sub instead of xlab to avoid collision with x tick marks.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With