You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R+Quarto自动生成PPT单图幻灯片失败求助

解决Quarto自动生成PPT幻灯片时图表不渲染的问题

问题出在你用knit_expand生成的R代码块不会被Quarto二次解析执行,仅作为文本输出,导致图表无法渲染。直接打印ggplot对象并配合幻灯片分隔语法即可解决,修正后的代码如下:

---
title: "test-auto"
format: pptx
---

```{r setup, include=FALSE}
library(tidyverse)
plot_list_q <-  list(
  ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point(),
  ggplot(mtcars, aes(x = hp, y = drat)) + geom_point()
)
walk2(plot_list_q, seq_along(plot_list_q), function(plot, idx) {
  # 输出幻灯片标题
  cat(paste0("# Plot ", idx, "\n\n"))
  # 直接打印图表,Quarto会自动渲染为幻灯片中的图片
  print(plot)
  # 用---分隔不同幻灯片(最后一张无需添加)
  if (idx != length(plot_list_q)) {
    cat("\n---\n\n")
  }
})
### 关键说明
- 用`#`标记的标题会被Quarto识别为PPT单张幻灯片的标题
- 直接打印ggplot对象时,Quarto会将其渲染为幻灯片内的图表
- `---`是Quarto中PPT幻灯片的分隔符,用于区分不同页面

内容的提问来源于stack exchange,提问作者Yann
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 14:58:28