r - 使用 knitr 并排插入 png 图像

标签 r markdown knitr

创建 html 文档时,如何将计算机中的 png 文件并排插入 rstudio?

以下效果很好(地块)

```{r, echo=FALSE,fig.width=4, fig.show='hold'}
 plot(cars)
plot(rnorm(100))
```

但是对于路径中的图像,只显示最后一个图像
 ```{r fig.width=3, fig.show='hold'}
   library(png)
  img <- readPNG("C:/path to my picture/picture.png")
  grid.raster(img)

  img2 <- readPNG("C:/path to my picture/picture2.png")
  grid.raster(img2)
  ```

最佳答案

您可以使用 knitr::include_graphics()因为这个接受路径向量作为参数。

那么你应该使用 fig.show='hold',fig.align='center'为了将它们绘制在同一行和 out.width="49%", out.height="20%" 上控制输出大小。

```{r, echo=FALSE,out.width="49%", 
out.height="20%",fig.cap="caption",fig.show='hold',fig.align='center'}
knitr::include_graphics(c("path/to/img1","path/to/img1"))
``` 

关于r - 使用 knitr 并排插入 png 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25415365/

相关文章:

linux - 在 R 中安装与 stringr 包相关的包时出错

http - 有什么办法可以在 markdown 中显示 URL 参数的 'wordwrap' 长 URL?

一起运行 R Markdown (check.Rmd ) 和 R knit (test.Rnw ) 文件

r - 如何在Rmarkdown中 "box"输出 "summary()"

r - 如何通过重新绘制图形来制作简单的 "animation"

r - 了解 RStudio 的工作区选项卡 lm 表示法

r - 根据变量的值将值从一个数据帧移动到另一个数据帧

vim - 文件类型特定的行空间设置

r - 如何使用 Google Analytics (rga) 编写动态报告

r - 在 Markdown 文件上使用 knit 但忽略一大块代码 - 采购 knitr 文件