1

I have a document wherein I am able to successfully display single images - referenced by a variable containing the image name - with chunks as follows:

```{r echo = FALSE, out.width = '100%'}
knitr::include_graphics(paste0(source_image_path,image_filename))
```

What I need is to be able to do this for two images and display them side by side with control over their respective width percentages. I tried this solution but one of the images is very grainy when imported this way, I cannot control the width percentages, and the total width is smaller than I'd like.

I also tried

```{r, out.width = "50%"}
img1 <- paste0(source_image_path,image_filename1)
img2 <-  paste0(source_image_path,image_filename2)
myimages <- list(img1,img2)
include_graphics(myimages)
```

based on what I found here; this looks better but I'm not sure how I can control the width percentages of the individual images. I tried using include_graphics(myimages,dpi = c(2,85)) without effect.

So how can I display 2 images, side by side, referenced by variables, and still control the individual width percentages?

pogibas
  • 27,303
  • 19
  • 84
  • 117
Rookatu
  • 1,487
  • 3
  • 21
  • 50

1 Answers1

1

Okay, I think I've got a solution.

I didn't know you could do this (my r markdown knowledge is pretty scant) but I tried modifying the chunk options as follows

```{r, out.width = c("20%","80%")}
img1 <- paste0(source_image_path,image_filename1)
img2 <-  paste0(source_image_path,image_filename2)
myimages <- list(img1,img2)
include_graphics(myimages)
```

and that seemed to work! A complete guess, but this is a great example of code working as intuition would cause you to expect.

Rookatu
  • 1,487
  • 3
  • 21
  • 50