Steve Buyske
Steve Buyske

Reputation: 393

How to import local image using knitr for markdown

I have an externally created png image in a local directory that I'd like to import to a report using knitr. The ultimate target filetype is html. I have no trouble getting my own figures to appear when I create them with R code, but I'm at a loss what I would have thought was a simpler problem.

While I'm at it, how would I import a figure for which I have a url?

Upvotes: 39

Views: 40171

Answers (2)

Ullas
Ullas

Reputation: 13

You can include image in knitted html by using knitr::include_graphics() in R Markdown.

knitr::include_graphics(rep('path_of_image.png'))

Make sure that you use ' / ' in path instead of ' \ '.

Upvotes: 0

Yihui Xie
Yihui Xie

Reputation: 30104

If you already have a local image, you can just use the HTML or markdown syntax to include it in your document. HTML syntax is <img src="path/to/your/image" /> and markdown is ![title](path/to/your/image).

Upvotes: 56

Related Questions