I am working with a large dataset, and have generated several figures with "StripPlot" method. Certainly the best way is to be able to add captions for each figure in the chunk, but not to export figures first, then import again with markdown syntax like !FIG. X. Captions of the 1st figure., !FIG. Y. Figure Two's caption.
After review some posts in SO and RStudio community, I am not able to find an answer. Currently I find two possible solutions:
- Add "fig.cap=c("FIG. X. Captions of the 1st figure.", "FIG. Y. Figure Y caption", "FIG. Z. Figure Z caption")" in r chunk, but looks like preceding captions are overlapped by following figures, thus only the caption of the last one is kept.
- Use "captioner" package, but after reading the examples, I really don't know how to use it.
There might be other solutions like use ggplot2, while I have to admit that is pretty new for me, and I will have to re-write those plot codes.
So I would like to know if there is an easy solution?
P.S. In other words, is there a way to add one or several new/empty line(s) after on figure?
Following is a sample code:
---
title: "How to add captions of two or more figures in one chunk with PDF output?"
author: "test"
date: "10/11/2020"
fontsize: 10pt
geometry: margin=0.75in
output:
pdf_document:
includes:
in_header: C:/Elekta/VersaHD/header.tex
number_sectins: yes
fig_caption: true
keep_tex: yes
html_document:
df_print: paged
self_contained: no
header-includes: \usepackage{caption, dcolumn}
---
\captionsetup[table]{labelformat=empty, justification=raggedright,singlelinecheck=false}
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::knit_hooks$set(crop = knitr::hook_pdfcrop)
```
### "Captions of two or more figures in one chunk with PDF output"
```{r, echo=FALSE, fig.asp=0.7, fig.show ='hold', dev=c('pdf', 'png'), message=FALSE, warning=FALSE, out.width='80%', paged.print=FALSE, crop=TRUE, fig.cap=c("FIG. X. Captions of the 1st figure.", "FIG. Y. Figure Y caption", "FIG. Z. Figure Z caption")}
x <- rnorm(10)
plot(x)
y <- rcauchy(10)
plot(y)
z <- runif(10)
plot(z)