Description

This brief tutorial explains how to add external images to an R Markdown notebook. While there are multiple ways to accomplish this, and very specific libraries that extend the core capabilities of Knitr, the scope of this tutorial is limited to the use of include_graphics() function.

Format - knitr::include_graphics(‘filename’)

Most of the work to manipulate image output to the HTML file is done in the code block header

  • fig.align {left, center, right, default}
  • out.width {px or percentage}
  • out.height {px or percentage}

Note: These settings only apply to HTML output. External images output to Word docs must me manually manipulated in Word.

Here are a few working examples

 

Example 1: 80% width, aligned to center

knitr::include_graphics('C:/Users/drhea/Desktop/fb_pic.jpg')

 

Example 2: “20% width, aligned left

 

Example 3: “100px width, aligned to right

 

Example 4: “100px width, 200px height, aligned to center