I'm trying to insert side-by-side images with one caption using knitr:
---
title: "XY"
author: "Doogan"
date: '`r format(Sys.Date(), "%B %d, %Y")`'
graphics: yes
output:
pdf_document:
toc: no
fig_caption: true
fontsize: 11pt
geometry: margin=1cm
---
```{r Directory, echo=F, message=F, warning=FALSE, paged.print=TRUE}
image.dir <- "your/directory/"
knitr::opts_chunk$set(echo = FALSE)
```
```{r 'xy_images'
,fig.show='hold',fig.pos='H',out.height='7.5cm',out.width='10cm',fig.cap="X
image (A) and Y image (B)"}
knitr::include_graphics(file.path(image.dir, 'X.png'))
knitr::include_graphics(file.path(image.dir, 'Y.png'))
```
The above code produces two stacked images with two separate (identical) captions:
When the fig.cap call is removed, the figures align correctly, but with no caption.
How can I alter my code chunk so that the images align side-by-side with only a single caption displayed?
Best Answer
I found a work around to this issue by plotting the .png images as rasters in the same plot window: