在 Quarto 和 R 中使用选项卡

问题描述 投票:0回答:1

我想在四开中添加标签。我将有 8 个选项卡,因此我决定进行循环以生成文本部分并在每个选项卡下打印点图。

我尝试以下代码。代码必须在每个选项卡下打印点图

```r

# Ligands-Receptors Couples (CellPhonDB)
::: {.panel-tabset .nav-pills}
```{r}
#| label: dotplotcpdb
#| fig.height: 10
#| fig.width: 18
#| results: 'asis'
 templateDtpcpdb <- "## %s
 Below are displayed the most significant interactions for the %s
 "
 for (i in 1:length(Fatlaslianacpdb)){
   cat('\n')
   cat(sprintf(templateDtpcpdb, unique(Fatlas.seu[[i]]$Sample), unique(Fatlas.seu[[i]]$Sample)))
   print(dotplotliana(i, Fatlaslianacpdb, Fatlaslianacpdb.sign))
  cat('\n')
}```
:::
```    

使用此代码时不会显示任何内容。你能告诉我哪里有错误吗? 谢谢你的帮助

r tabs markdown quarto rnotebook
1个回答
0
投票

这里有一个非常好的使用方式

purrr::walk()
:

---
format: html
---

# Ligands-Receptors Couples (CellPhonDB)


::: panel-tabset
```{r}
#| results: asis
#| label: dotplotcpdb

row_nr = 1:8
library(ggplot2)
purrr::walk(row_nr,
      \(x) {
        cat('### Plot', x, '\n\n')
        print(mtcars[x:(x+1),] |> 
                ggplot(aes(x = disp, y = mpg)) +
                geom_point())
        
        cat('\n\n')
      })
```

:::

© www.soinside.com 2019 - 2024. All rights reserved.