使用grid.raster在Rmarkdown循环中查看png文件只绘制一个图像

时间:2018-02-15 22:14:21

标签: r loops r-markdown

我有不同数量的png文件。在Rmarkdown中,我试图创建一个新标题并显示png文件。

我在下面创建了一个最小的例子。

我经常在各种其他类似的绘图案例中使用下面显示的循环结构,但是使用grid.raster我只得到最后一个绘图。

寻求帮助以解决此问题。

---
title: "Buggy Looping with grid.raster"
author: "Author"
output: html_document
---

```{r}
png("test1.png") ; heatmap(as.matrix(iris[,-5])); dev.off()
png("test2.png") ; heatmap(as.matrix(mtcars))   ; dev.off()
pltNames <- list.files(pattern = "^test.+\\.png$")
```

```{r, results='asis'}
for (i in seq_len(length(pltNames))){
  cat('\n')  
  cat("# This is a heading for ", pltNames[i], "\n") 
  cat('\n')  
  grid::grid.raster(png::readPNG(pltNames[i]))
  cat('\n') 
}
```

0 个答案:

没有答案
相关问题