我一直在尝试使用以下脚本在组合图下方制作 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 爵士提供)组合在左下部分联合地块?
关于如何解决这个问题的任何建议?非常感谢。