I have been trying to make a 2 to 3-line figure caption below the combined plots using the following script:
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)
But when I tried to execute this command, it still forms a one-liner caption.
UPDATE:
Thank you Sir @baptiste for your suggestions. Now I know that newline command is incompatible with plotmath. However, when I tried to incorporate the new script, my plots disappeared and did not combine with the caption.
Now my query is:
- How am I going to incorporate the script suggested by Sir @baptiste to my original script (as shown above), and combine the two plots (pl and pl1) with the caption (provided by Sir @baptiste) at the lower left portion of the combined plots?
Any suggestions on how I can fix this? Thank you very much.