首页 > 解决方案 > 官员 r 包用于创建具有并排内容的幻灯片 - 内容仅出现在一个部分中

问题描述

R尽管我尽了最大努力,但我无法在使用package生成的 Powerpoint 幻灯片中并排加载任何内容officer。我想要的是内容(右侧的来源图像或情节等,左侧的文本)。这是我的工作流程:

plot.gg <- ggplot(iris, aes(Sepal.Length, Petal.Width)) + 
   geom_line()

library(officer)
read_pptx()  %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with("text",  location = ph_location_type(type = "body", index = 4)) %>%
  ph_with(plot.gg, location = ph_location_type(type = "body", index = 3)) %>%
  print(target = "test.pptx") 

上述代码的结果是两条内容都出现在右侧。我可以在左侧以标题的形式获取文本,ph_with_text(type = "title", index=1, str = "title")但尽管我尽了最大努力,但幻灯片的左侧没有出现标题或内容。

标签: rofficerreporters

解决方案


您可以明确指定您的第一次调用ph_with不会出现在右侧。

read_pptx()  %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with("text",  location = ph_location_type(type = "body", index = 4, position_right = F)) %>%
  ph_with(plot.gg, location = ph_location_type(type = "body", index = 3)) %>%
  print(target = "test.pptx") 

推荐阅读