比方说,我在列表中有ggplot图
plts <- list(plt1=qplot(1:10),plt2=qplot(2:3))我想用grid.arrange和标题绘制:
do.call(grid.arrange,c(plts,top='a title'))困难在于我想在grid.arrange标题中使用一些plotmath表达式。 如果我做
do.call(grid.arrange,c(plts,top=expression('a title[2]') ))R将do.call的第二个参数强制转换为表达式而不是list,do.call抛出错误。 我尝试手动设置类“列表”,但无济于事。 什么是正确的方法来解决这个问题?
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?
最满意答案
根据grid.arrange手册:
顶部可选字符串或grob
所以在oder中使用表达式,你应该提供一个grob。 例如,如果要将2绘制为下标:
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])) ))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])) ))更多推荐
发布评论