Search code examples
imagermarkdownknitrpandoc

How to set size for local image using knitr for markdown?


I have a local image that I would like to include in an .Rmd file which I will then knit and convert to HTML slides with Pandoc. Per this post, this will insert the local image :
![Image Title](path/to/your/image)

Is there a way to modify this code to also set the image size?


Solution

  • You can also read the image using png package for example and plot it like a regular plot using grid.raster from the grid package.

    ```{r fig.width=1, fig.height=10,echo=FALSE}
    library(png)
    library(grid)
    img <- readPNG("path/to/your/image")
     grid.raster(img)
    ```
    

    With this method you have full control of the size of you image.