add and resize a local image to a .Rmd file in RStudio that will produce a pdf
From @tmpname12345
You can use raw latex to include a figure in pdf_output: \includegraphics[width=250pt]{path/file.png}
You can also specify the size of the image like so:
![](filepath\file.jpg){ width=50% }
The width
and height
attributes on images are treated specially. When used without a unit, the unit is assumed to be pixels. However, any of the following unit identifiers can be used: px
, cm
, mm
, in
, inch
and %
. There must not be any spaces between the number and the unit.
Source: Pandoc's RMarkdown Documentation - Images
In case anyone arrives here from google looking to insert an image into an RMarkdown html_document:
Insert directly
This method is arguably the easiest to change size
<img src="mypic.png" alt="drawing" width="200" height="50"/>
Another way
Note you can mix measurements like so: height="200" width=60%
![some caption text here](mypic.png){height="200" width=60% }
Insert via RMarkdown chunk
knitr::include_graphics("mypic.png")
Insert directly from URL
```{r echo=FALSE, out.width = '60%'}
image_url <- "http://www.example.com/mypic.png"
```
<center><img src="`r image_url`"></center>