To get math expressions in facet_grid labels, you can use
labeller=label_parsed:
m <- mpg
levels(m$drv) <- c("x[1]", "y^2", "z+3")
ggplot(m, aes(x = displ, y = cty)) + geom_point() +
facet_grid(. ~ drv, labeller = label_parsed)
But this doesn't work with facet_wrap -- it's kind of complicated, but
the root reason it doesn't work has to do with the way the facets are
generated when you have two faceting variables. Notice the difference
between these two:
ggplot(mpg, aes(x = displ, y = cty)) + geom_point() +
facet_grid(. ~ drv + fl)
ggplot(mpg, aes(x = displ, y = cty)) + geom_point() +
facet_wrap( ~ drv + fl)
More information on why it won't work here:
https://github.com/hadley/ggplot2/pull/656
-Winston