如何创建一个四开本的 PowerPoint 演示文稿,其中并排显示两幅图,并在每张幻灯片的底部添加描述性文字(如屏幕截图所示)?我的问题是,文本出现在第二张幻灯片上,而不是同一张幻灯片上两幅图的底部。
---
title: "iris Presentation"
format: pptx
---
parts of the code are from: https://github.com/quarto-dev/quarto-cli/discussions/2403
```{r, include=FALSE}
library(tidyverse)
# Create histogram for each species
spec_name <- unique(iris$Species)
make_hist <- function(spec) {
iris |>
filter(Species == spec) |>
ggplot(aes(x = Petal.Length)) +
geom_histogram(bins = 10, fill = "steelblue", color = "white") +
labs(title = paste("Petal Length Histogram -", spec))
}
list_hist <- map(spec_name, make_hist)
# Create a second set of plots (random scatter plots)
make_random_plot <- function() {
tibble(x = rnorm(50), y = rnorm(50)) |>
ggplot(aes(x, y)) +
geom_point(color = "darkorange") +
labs(title = "Random Scatter Plot")
}
list_random <- map(spec_name, ~ make_random_plot())
# Combine into a data frame
df <- tibble(spec = spec_name,
plot1 = list_hist,
plot2 = list_random)
```
```{r}
#| output: asis
res <- pmap_chr(df, \(spec, plot1, plot2) {
knitr::knit_child(text = c(
paste0("## ", spec, " - Summary"),
"```{r}",
"#| echo: false",
"#| layout-ncol: 2",
"plot1",
"plot2",
"```",
"",
paste("This slide shows the distribution of Petal Length for", spec,
"alongside a comparison scatter plot of random values.")
), envir = environment(), quiet = TRUE)
})
cat(res, sep = '\n')
```
期望输出: