创建 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/