Including an image in R Markdown PDF table

会有一股神秘感。 提交于 2021-02-11 12:23:32

问题


I am working in R Markdown, knitting to PDF.

I thought the following code should create a table with a local image, but it is not working. Any help would be greatly appreciated!


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))


回答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))
```

I just used the link in the comments and fit your question into the code. if you wanted different pictures for each row, you maybe need to save the file names into a vector. In the example you could also use images from a webpage



来源:https://stackoverflow.com/questions/63239214/including-an-image-in-r-markdown-pdf-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!