将本地图像添加并调整大小到 RStudio 中的 .Rmd 文件,该文件将生成 pdf
add and resize a local image to a .Rmd file in RStudio that will produce a pdf
我正在尝试将本地图像添加到 RStudio 中的 .Rmd
文件并调整其大小,该文件将生成 pdf。我可以使用
轻松添加文件
![My caption.](path/file.png)
但是我还没有弄清楚如何控制图片的大小。我尝试了带有宽度属性的 HTML 代码,但图像不会出现(我认为这仅在输出到 HTML 时有效)。
<img src="path/file.png" width="200px" />
我无法让 this idea 工作:
![My caption.](path/file.png =250x)
有没有办法修改Rmarkdown脚本,只用RMarkdown和base R修改本地图片的大小?
a suggestion 可以使用 png
和 grid
包,但我的问题仅限于 base R。但是,对于其他用户,我认为这看起来是一个不错的解决方案。
来自@tmpname12345
您可以使用原始乳胶在 pdf_output 中包含一个数字:\includegraphics[width=250pt]{path/file.png}
一个较长的乳胶示例。
\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)
```
您还可以像这样指定图像的大小:
![](filepath\file.jpg){ width=50% }
图像的 width
和 height
属性被特殊处理。在没有单位的情况下使用时,单位假定为像素。但是,可以使用以下任何单位标识符:px
、cm
、mm
、in
、inch
和 %
。数字和单位之间不能有空格
以防有人从 google 来到这里,希望将图像插入 RMarkdown html_document:
直接插入
这种方法可以说是最容易改变尺寸的方法
<img src="mypic.png" alt="drawing" width="200" height="50"/>
另一种方式
请注意,您可以像这样混合测量:height="200" width=60%
![some caption text here](mypic.png){height="200" width=60% }
通过 RMarkdown 块插入
knitr::include_graphics("mypic.png")
直接从 URL
插入
```{r echo=FALSE, out.width = '60%'}
image_url <- "http://www.example.com/mypic.png"
```
<center><img src="`r image_url`"></center>
我正在尝试将本地图像添加到 RStudio 中的 .Rmd
文件并调整其大小,该文件将生成 pdf。我可以使用
![My caption.](path/file.png)
但是我还没有弄清楚如何控制图片的大小。我尝试了带有宽度属性的 HTML 代码,但图像不会出现(我认为这仅在输出到 HTML 时有效)。
<img src="path/file.png" width="200px" />
我无法让 this idea 工作:
![My caption.](path/file.png =250x)
有没有办法修改Rmarkdown脚本,只用RMarkdown和base R修改本地图片的大小?
a suggestion 可以使用 png
和 grid
包,但我的问题仅限于 base R。但是,对于其他用户,我认为这看起来是一个不错的解决方案。
来自@tmpname12345
您可以使用原始乳胶在 pdf_output 中包含一个数字:\includegraphics[width=250pt]{path/file.png}
一个较长的乳胶示例。
\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)
```
您还可以像这样指定图像的大小:
![](filepath\file.jpg){ width=50% }
图像的 width
和 height
属性被特殊处理。在没有单位的情况下使用时,单位假定为像素。但是,可以使用以下任何单位标识符:px
、cm
、mm
、in
、inch
和 %
。数字和单位之间不能有空格
以防有人从 google 来到这里,希望将图像插入 RMarkdown html_document:
直接插入
这种方法可以说是最容易改变尺寸的方法
<img src="mypic.png" alt="drawing" width="200" height="50"/>
另一种方式
请注意,您可以像这样混合测量:height="200" width=60%
![some caption text here](mypic.png){height="200" width=60% }
通过 RMarkdown 块插入
knitr::include_graphics("mypic.png")
直接从 URL
插入```{r echo=FALSE, out.width = '60%'}
image_url <- "http://www.example.com/mypic.png"
```
<center><img src="`r image_url`"></center>