首页 > 解决方案 > Rmarkdown 图片库

问题描述

任何人都知道 Rmarkdown 的任何图片库包或创建画廊的好方法吗?我刚刚开始尝试一些香草代码,但还有很长的路要走。只是想在进入这个兔子洞之前与社区核实一下我是否遗漏了一些已知或明显的解决方案。

下面是一个工作示例。

在此处输入图像描述

---
title: "Gallery"
output:
  html_document:
    theme: united
---

<br>

```{r,include=FALSE}
paths <- c(
  "https://images.pexels.com/photos/7604423/pexels-photo-7604423.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940",
  "https://images.pexels.com/photos/5483373/pexels-photo-5483373.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940",
  "https://images.pexels.com/photos/4982737/pexels-photo-4982737.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940",
  "https://images.pexels.com/photos/3773652/pexels-photo-3773652.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
)
len <- length(paths)
width <- paste0(100/len,"%")
```
```{r,echo=FALSE,fig.show="hold",out.width=width}
knitr::include_graphics(paths)
```


```{r,include=FALSE}
paths <- c(
  "https://images.pexels.com/photos/3845111/pexels-photo-3845111.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260",
  "https://images.pexels.com/photos/3933996/pexels-photo-3933996.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260",
  "https://images.pexels.com/photos/1033729/pexels-photo-1033729.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
)
len <- length(paths)
width <- paste0(100/len,"%")
```

```{r,echo=FALSE,fig.show="hold",out.width=width}
knitr::include_graphics(paths)
```

标签: rr-markdownr-distill

解决方案


最终创建了一个包,因为我找不到任何东西。https://github.com/royfrancis/pixture

---
title: "Gallery"
output:
  html_document:
    theme: united
---


```{r}
paths <- c(
  "https://images.pexels.com/photos/7604423/pexels-photo-7604423.jpeg",
  "https://images.pexels.com/photos/5483373/pexels-photo-5483373.jpeg",
  "https://images.pexels.com/photos/4982737/pexels-photo-4982737.jpeg",
  "https://images.pexels.com/photos/3773652/pexels-photo-3773652.jpeg"
)

library(pixture)
pixture(paths)
```

在此处输入图像描述


推荐阅读