I am trying to put 4 plots together and add a long caption (Figure caption) underneath of the plots. However, when I try to add the caption, it puts the wrapped caption over top of the graphs. Additionally, there is a part of my caption that needs to be superscripted in the middle, but the caption won't allow for the superscript.
The following code is what I have been trying.
caption<-"Long arbitrary caption with word^superscripted in the middle. "
annotate_figure((ggarrange(HR1Plot,HR3Plot,HR12Plot,HR24Plot,
ncol=2,nrow=2,
labels=c("A","B","C","D"))),
fig.lab = caption,
fig.lab.pos = "bottom.left"
)
The caption is now over the entire graph instead of under the graphs. I'm also asking for help on how to superscript the word in the middle.
One option to fix your issue would be to switch to the
patchworkpackage to glue your plots together and which allows to add a title, caption, ... the same way as we would do for a singleggplot. Second, to fix your issue with the superscript you could create your caption as a?plotmathexpression.Using a minimal reproducible example based on
mtcars:EDIT First,
wrap_plotsrequires thepatchworkpackage which you have to install and attach as I do. Second,plotmathcould be a bit tricky, i.e. you have to wrap the,in quotes, i.e. use",". Also besides the~separattor which adds a space there is also a*separator.However, while
plotmathis the way to go for math expression, in your case I would suggest to switch to e.g.ggtextto add your superscript text. The latter allows to add use some basic HTML, CSS or markdown to format text, e.g. you could add a superscript via a<sup>tag. Additionally, as you caption is quite longggtextmakes it easy to split your caption over mutliple lines (whichplotmathdoes not) and viaggtext::elment_textbox_simpleyou could achieve that more or less automatically: