在gridarrange标题中的plotmath(plotmath in gridarrange title)

编程入门 行业动态 更新时间:2024-10-10 02:16:54
在gridarrange标题中的plotmath(plotmath in gridarrange title)

比方说,我在列表中有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])) ))

更多推荐

本文发布于:2023-08-04 20:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1421468.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   gridarrange   title   plotmath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!