use*_*225 5 powerpoint r r-markdown
我正在使用 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)
```
:::
::::::::::::::
Run Code Online (Sandbox Code Playgroud)
我希望在幻灯片的图下方添加“摘要(汽车)”部分,但它被简单地排除了。
我无法成功使用 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()
Run Code Online (Sandbox Code Playgroud)