1

I am trying to reproduce an image from pandoc to Rmarkdown.

The pandoc way :

 ![](https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80)

My trial Rmarkdown:

url <- "https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80"

knitr::include_graphics(url, dpi = 600)

I am able to knit the file and able to generate the image same as pandoc but also additionally would like to set the output width of the figure to 600px which I am trying by placing in dpi=600.

I am skeptical about that is the image actually resized after performing this or is there an alternative way?

Ranji Raj
  • 778
  • 4
  • 18
  • 1
    Maybe this will help https://stackoverflow.com/questions/15625990/how-to-set-size-for-local-image-using-knitr-for-markdown – Ronak Shah May 03 '21 at 04:36

1 Answers1

2

For me the dpi argument of knitr::include_graphics() also doesn't change the size of the image for HTML or DOCX output. What does work though issetting the chunk-option out.width. You can use pixel values (see below) or percent (e.g. "25%").

```{r out.width="300px"}
url <- "https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80"
knitr::include_graphics(url)

```

See chapter 5.4 of the R-Markdown Cookbook for more details.

Till
  • 3,845
  • 1
  • 11
  • 18