如何使用 knitr 为降价设置本地图像的大小? [英] How to set size for local image using knitr for markdown?

查看:24
本文介绍了如何使用 knitr 为降价设置本地图像的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地图像,我想将其包含在 .Rmd 文件中,然后我将 knit 并使用 Pandoc.根据这篇文章,这将插入本地图像:
![图片标题](path/to/your/image)

I have a local image that I would like to include in an .Rmd file which I will then knit and convert to HTML slides with Pandoc. Per this post, this will insert the local image :
![Image Title](path/to/your/image)

有没有办法修改此代码以设置图像大小?

Is there a way to modify this code to also set the image size?

推荐答案

您还可以使用 png 包读取图像,例如使用 grid.raster 来自 grid 包.

You can also read the image using png package for example and plot it like a regular plot using grid.raster from the grid package.

```{r fig.width=1, fig.height=10,echo=FALSE}
library(png)
library(grid)
img <- readPNG("path/to/your/image")
 grid.raster(img)
```

使用此方法,您可以完全控制图像的大小.

With this method you have full control of the size of you image.

这篇关于如何使用 knitr 为降价设置本地图像的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆