我正在尝试将本地图像添加并调整为RStudio中的.Rmd
文件,该文件将生成pdf。我可以使用

但我还没弄清楚如何控制图像的大小。我尝试使用宽度属性的HTML代码,但图像不会出现(我认为只有在输出到HTML时才有效)。
<img src="path/file.png" width="200px" />
我无法让this idea工作:

有没有办法修改Rmarkdown脚本以仅使用RMarkdown和base R来修改本地图像的大小?
使用png
和grid
软件包a suggestion,但我的问题仅限于基础R.但是,对于其他用户,我认为这看起来是一个很好的解决方案。
答案 0 :(得分:8)
你也可以像这样指定图像的大小:
{ width=50% }
图片上的width
和height
属性经过特殊处理。在没有单位的情况下使用时,假设该单位是像素。但是,可以使用以下任何单位标识符:px
,cm
,mm
,in
,inch
和%
。数字和单位之间不得有任何空格。
答案 1 :(得分:7)
来自@ tmpname12345
您可以使用原始乳胶在pdf_output中包含一个数字:\includegraphics[width=250pt]{path/file.png}
答案 2 :(得分:2)
如果有人从谷歌到达这里,希望将图像插入RMarkdown html_document:
可以说这种方法最容易改变大小
<img src="mypic.png" alt="drawing" width="200" height="50"/>
请注意,您可以像这样混合测量:height="200" width=60%
{height="200" width=60% }
knitr::include_graphics("mypic.png")
```{r echo=FALSE, out.width = '60%'}
image_url <- "http://www.example.com/mypic.png"
```
<center><img src="`r image_url`"></center>
答案 3 :(得分:1)
乳胶的一个较长的例子。
\begin{figure}
\includegraphics[width=250pt]{../images/pricePlot2006_1.5.png}
\caption{Prices through time.}\label{fig:1}
\end{figure}
.Rmd中创建的其他数字会自动编号。
```{r namedBlock, fig.cap = "Lots of cars."}
plot(mtcars)
```