You can introduce a line break inside an expression:
bquote(atop("first line",
"second line" ~ x ^ 2))
(I’m using bquote
rather than expression
here – both work in this case.)
Execute demo(plotmath)
for more information and look at the documentation for atop
.
boxplot
apparently has some trouble interpreting expressions in its title. A simple fix is to plot the title separately:
boxplot(data, main = '')
title(bquote(atop("first line", "second line" ~ x ^ 2)))