4
votes

I have ggplot plots in a list, say

plts <- list(plt1=qplot(1:10),plt2=qplot(2:3))

which I would like to plot using grid.arrange and a title:

do.call(grid.arrange,c(plts,top='a title'))

The difficulty is I would like some plotmath expressions in that grid.arrange title. If I do

do.call(grid.arrange,c(plts,top=expression('a title[2]') ))

R coerces the second argument to do.call to an expression type rather than list, and do.call throws an error. I tried setting the class manually to "list" but to no avail. What is the proper way to go about this?

1

1 Answers

2
votes

according to manual of grid.arrange:

top optional string, or grob

so in oder to use expression, you should provide a grob. for example, If you want to plot 2 as subscript:

library(grid)
grid.arrange(grobs = plts,top= grid.text(expression('a' ~ title[2])))
# or
do.call(grid.arrange, list(grobs = plts,top = grid.text(expression('a' ~ title[2])) ))