image - 如何使用knitr为markdown设置本地镜像的大小?

标签 image r markdown knitr pandoc

我有一个本地镜像,我想将其包含在 .Rmd 中文件,然后我将 knit并使用 Pandoc 转换为 HTML 幻灯片。每this post ,这将插入本地镜像:
![Image Title](path/to/your/image)

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

最佳答案

这个问题很老了,但仍然受到很多关注。由于现有答案已经过时,这里有一个更新的解决方案:

调整本 map 片大小

截至 knitr 1.12 ,有函数include_graphics 。来自 ?include_graphics (强调我的):

The major advantage of using this function is that it is portable in the sense that it works for all document formats that knitr supports, so you do not need to think if you have to use, for example, LaTeX or Markdown syntax, to embed an external image. Chunk options related to graphics output that work for normal R plots also work for these images, such as out.width and out.height.

示例:

```{r, out.width = "400px"}
knitr::include_graphics("path/to/image.png")
```

优点:

<小时/>

包括生成的图像

要组成在 block 中生成的图的路径(但不包括在内), block 选项 opts_current$get("fig.path") (图形目录的路径)以及 opts_current$get("label") (当前 block 的标签)可能有用。以下示例使用 fig.path包含在第一个 block 中生成(但未显示)的两个图像中的第二个:

```{r generate_figures, fig.show = "hide"}
library(knitr)
plot(1:10, col = "green")
plot(1:10, col = "red")
```

```{r}
include_graphics(sprintf("%sgenerate_figures-2.png", opts_current$get("fig.path")))
```

图形路径的一般模式是 [fig.path]/[chunklabel]-[i].[ext] ,其中chunklabel是生成图的 block 的标签,i是绘图索引(在该 block 内)和 ext是文件扩展名(RMarkdown 文档中默认 png)。

关于image - 如何使用knitr为markdown设置本地镜像的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15625990/

相关文章:

image - VBA:复制单元格,粘贴为图片,然后另存为图片?

image - 符号/图像分类建议

java - 如何在java中围绕特定点而不是图像中心旋转图像?

r - R formattable上的列宽相等

r - 如何逐步提取mlr3调谐图?

javascript - 在新图像完全加载时添加微调器

sublimetext3 - 如何使用 Sublime Text 在 Markdown 中快速插入图像路径

markdown - 在 Jekyll 中,有没有一种简洁的方法来渲染 Markdown 部分?

ios - 如何在 UITextview swift 中使用 linkTextAttributes

r - R : argument is not numeric or logical: returning NA, as.integer()