These lines check if the top = argument is a character, and if so returns textGrob(top). If it's an expression, however, it doesn't do anything at all. The workaround for top = expression(xyz) is to call top = textGrob(expression(xyz)), but it feels to me like it should call it automatically.
p <- ggplot(mtcars, aes(disp, mpg)) + geom_point() +
stat_smooth(method = "lm", formula = y~poly(x, 2))
# works, but it's not parsed
grid.arrange(p, top = "y == b[0] + b[1]*x + b[2]*x^2")
# doesn't work, prints only p, no top grob
grid.arrange(p, top = expression(y == b[0] + b[1]*x + b[2]*x^2))
# works, but you have to set heights manually
grid.arrange(textGrob(expression(y == b[0] + b[1]*x + b[2]*x^2)), p)
# works, but it's more verbose
grid.arrange(p, top = textGrob(expression(y == b[0] + b[1]*x + b[2]*x^2)))
https://github.com/baptiste/gridextra/blob/master/R/arrangeGrob.r#L153
These lines check if the
top =
argument is a character, and if so returnstextGrob(top)
. If it's an expression, however, it doesn't do anything at all. The workaround fortop = expression(xyz)
is to calltop = textGrob(expression(xyz))
, but it feels to me like it should call it automatically.