【问题标题】:Including an image in R Markdown PDF table在 R Markdown PDF 表中包含图像
【发布时间】:2020-11-24 02:19:59
【问题描述】:

我正在使用 R Markdown 编写 PDF。

我认为以下代码应该使用本地图像创建一个表,但它不起作用。任何帮助将不胜感激!


column1 <- c("1", "2", "3")
column2 <- c("a", "b", "c")
column3 <- c("x", "y", "z")

dat <- data.frame(column1, column2, column3)

dat$column1[1] <- "![image1](green.png){ width=25px }"

print(kable(dat))

【问题讨论】:

标签: r image pdf r-markdown knitr


【解决方案1】:
---
title: "pic in column"
author: "test"
date: "2014/08/03"
output: html_document
---

```{r results='asis'}
library(knitr)
column1 <- c("1", "2", "3")
column2 <- c("a", "b", "c")
column3 <- c("x", "y", "z")

dat <- data.frame(column1, column2, column3)

dat$column1<- sprintf('![](green.png)')

print(kable(dat))
```

我刚刚使用了 cmets 中的链接并将您的问题放入代码中。如果您想要每行有不同的图片,您可能需要将文件名保存到矢量中。在示例中,您还可以使用网页中的图像

【讨论】:

  • 嘿丹尼尔!非常感谢您在回复中付出的努力。不幸的是,这个解决方案不适用于 PDF 输出,这是我目前正在努力解决的问题。不过真的很感激!
  • 如果将其渲染为 HTML 然后打印为 PDF 会怎样?
猜你喜欢
  • 2021-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-08
  • 2020-01-31
  • 2018-03-31
  • 2014-08-31
  • 2019-06-02
相关资源
最近更新 更多