In my rmarkdown document, I want to include plots side by side to save space. For example, I want to include:
plot(rnorm(100))
hist(runif(100))
or
plot(rnorm(100))
hist(runif(100))
I don't really care if there is one caption for both subplots or one caption for each subplot. I just really want to include figures side by side and have some way to refer to them (Figure 1, etc). Does anyone have suggestions? I have this in my header:
header-includes: - \usepackage{subfig}
When I don't have "fig.show='hold' " in my chunks, all of my captions work fine but my plots do not show up side by side. When I add fig.show='hold', the layout looks great but the captions disappear.
Adapting my answer from this post, you can combine cross-referencing by including the output format
bookdown::pdf_document2
". Note that I am manually appending the subfigure letter to the cross reference i.e.\@ref(fig:fig-sub)a
: