首页 > 解决方案 > 如何在 RMarkdown 的 PowerPoint 幻灯片中包含多个数字?

问题描述

我正在使用 R-markdown 生成 PowerPoint 演示文稿。如何在幻灯片上包含多个图形或“内容”?

我已尝试修改 PowerPoint 模板以包含以下三个内容块: 图像 但我无法将内容添加到右下角的对象。

---
title: "pp_test"
output: 
  powerpoint_presentation:
    reference_doc: pp_template3.pptx
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

# Slide with 3 contents

:::::::::::::: {.columns}
::: {.column}
Text
:::
::: {.column}
```{r pressure, echo=FALSE, fig.cap="Caption"}
plot(pressure)
```
:::
::: {.column}
```{r cars, echo = TRUE}
summary(cars)
```
:::
::::::::::::::

我希望在幻灯片的情节下方添加“摘要(汽车)”部分,但它被简单地排除在外。

标签: rr-markdownpowerpoint

解决方案


我使用 r-markdown 无法成功,所以我研究了其他包并找到了“officer”,它能够产生我想要的结果。

它不支持不是数据框的表,因此我无法添加“摘要(汽车)”部分。但是以两个图为例,我能够产生结果 结果与官员

使用以下代码

library(officer)
library(magrittr)
library(ggplot2)
setwd(mydir)

my_plot <- ggplot(data=pressure) +
  geom_point(aes(temperature, pressure))
my_summary <- as.str(summary(cars))

my_pres <- 
  read_pptx("pp_template3.pptx") %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with_text(type = "title", index = 1, str = "The title") %>%
  ph_with_gg(type = "body", index = 1, value = my_plot) %>%
  ph_with_text(type = "body", index = 2, str = "Some text") %>%
  ph_with_gg(type = "body", index = 3, value = my_plot) %>%
  print(target = "test_pp_officer.pptx") %>%
  invisible()

推荐阅读