【发布时间】:2016-03-15 01:21:38
【问题描述】:
我一直在尝试使用以下脚本在组合图下方制作 2 到 3 行的图形标题:
library(grid)
library(gridExtra)
library(ggplot2)
g1 <- ggplotGrob(pl) #pl is my plot 1
g2 <- ggplotGrob(pl1) #pl1 is my plot 2
g <- rbind(g1, g2) #this combines my two plots
caption <- textGrob(expression(paste(bold("Figure 1"), ". This is the first line with a", italic( " scientific name."),"\nThis should be the second line.","\nThis is the third line.")), hjust=0, x=0) #caption to be incorporated at the lower left of the combined plots
g <- gtable::gtable_add_rows(g, unit(2,"mm") + grobHeight(caption), -1) #incorporating the combined plots with the caption
g <- gtable::gtable_add_grob(g, caption, nrow(g), l = 4, r = ncol(g)) #incorporating the combined plots with the caption
grid.newpage()
grid.draw(g)
但是当我尝试执行这个命令时,它仍然形成一个单行标题。
更新:
感谢@baptiste 先生的建议。现在我知道换行命令与 plotmath 不兼容。但是,当我尝试合并新脚本时,我的情节消失了,并且没有与标题结合。
现在我的查询是:
- 如何将@baptiste 爵士建议的脚本合并到我的原始脚本中(如上所示),并将两个情节(pl 和 pl1)与左下角的标题(@baptiste 爵士提供)结合起来合并地块的一部分?
关于如何解决此问题的任何建议?非常感谢。
【问题讨论】: