【问题标题】:Inserting images from url to Rmakdown using the knitr::include_graphics使用 knitr::include_graphics 将图像从 url 插入到 Rmakdown
【发布时间】:2021-07-25 10:38:42
【问题描述】:

我正在尝试将图像从 pandoc 复制到 Rmarkdown

pandoc 方式:

 ![](https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80)

我的试用 Rmarkdown:

url <- "https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80"

knitr::include_graphics(url, dpi = 600)

我能够编织文件并能够生成与 pandoc 相同的图像,但还想将图形的输出 width 设置为600px,我正在尝试将其放入dpi=600.

我怀疑执行此操作后图像实际上是否调整了大小,还是有其他方法?

【问题讨论】:

标签: r r-markdown knitr


【解决方案1】:

对我来说,knitr::include_graphics()dpi 参数也不会更改 HTML 或 DOCX 输出的图像大小。设置块选项out.width 有什么作用。您可以使用像素值(见下文)或百分比(例如“25%”)。

```{r out.width="300px"}
url <- "https://images.unsplash.com/photo-1563204996-8965f0a4a860?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80"
knitr::include_graphics(url)

```

有关详细信息,请参阅R-Markdown Cookbook 的第 5.4 章。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 2016-12-03
    • 1970-01-01
    • 2014-10-14
    • 2017-04-17
    • 1970-01-01
    • 2021-10-10
    相关资源
    最近更新 更多