Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 551
Steve Buyske Avatar asked May 09 '12 13:05

Steve Buyske


People also ask

How do I add graphics to R markdown?

Including images in an R markdown File. We can include an image using {knitr} and the include_graphics() function, e.g. Typically the chunk would use echo = FALSE as we don't want to see the actual R code.

What is the function of knitr in creating markdown document?

knitr is an engine for dynamic report generation with R. It is a package in the programming language R that enables integration of R code into LaTeX, LyX, HTML, Markdown, AsciiDoc, and reStructuredText documents. The purpose of knitr is to allow reproducible research in R through the means of literate programming.


1 Answers

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).

like image 58
Yihui Xie Avatar answered Oct 05 '22 12:10

Yihui Xie