I am trying to arrange a few plots generated by ggplot2
using the gridExtra
package.
library(ggplot2)
library(gridExtra)
p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point()
p2 <- ggplot(iris, aes(Sepal.Length, Petal.Length)) + geom_point()
p3 <- ggplot(iris, aes(Species, Sepal.Width)) + geom_point()
p4 <- ggplot(iris, aes(Sepal.Width, Petal.Width)) + geom_point()
grid.arrange(main="CO2Exp", p1, p2, p3, p4, ncol=2)
When I try to have a main title, the follwing works fine.
grid.arrange(main="CO2Exp", p1, p2, p3, p4, ncol=2)
But when I try with expression
to get a subscript,
grid.arrange(main=expression(paste(CO[2], "Exp")), p1, p2, p3, p4, ncol=2)
I get the following error
Error in valid.data(rep(units, length.out = length(x)), data) :
no 'grob' supplied for 'grobwidth/height' unit
How to fix this?
I am using R
_3.1.3, gridExtra
_0.9.1 and ggplot2
_1.0.1