【问题标题】:Officer: power point slides with ggplot(s) AS IMAGES官员:带有ggplot(s)的power point幻灯片作为图像
【发布时间】:2020-12-13 21:56:47
【问题描述】:

下面的代码使用基于矢量的 ggplot 对象创建了一个 PowerPoint 幻灯片,效果很好。

现在我想要同一张幻灯片,带有图形作为图像(例如 PNG,不可编辑)。我认为使用 ph_with_gg(plot, resolution) 等可以做到这一点,但现在已弃用。

这可以通过在 PowerPoint 中复制/粘贴为图像来实现,但这很乏味。我的主要原因是大型数据集和 powerpoint 因过多的单个对象而变慢。

library(ggplot2)
library(officer)
library(rvg)
library(magrittr)
data(iris)

read_pptx() %>%
  add_slide(layout='Title and Content',master='Office Theme') %>%
  ph_with('Iris Sepal Dimensions', location = ph_location_type(type="title")) %>%
  ph_with(dml( ggobj=
                 ggplot(iris, aes(x=Sepal.Length,y=Sepal.Width,col=Species)) +
                 geom_point()), location = ph_location_type(type="body")) %>%
  print('iris_presentation.pptx')

【问题讨论】:

    标签: r ggplot2 officer


    【解决方案1】:

    在这种情况下,你只需要不调用rvg::dml

    library(ggplot2)
    library(officer)
    library(magrittr)
    data(iris)
    
    read_pptx() %>%
      add_slide(layout='Title and Content',master='Office Theme') %>%
      ph_with('Iris Sepal Dimensions', location = ph_location_type(type="title")) %>%
      ph_with(
        ggplot(iris, aes(x=Sepal.Length,y=Sepal.Width,col=Species)) + geom_point(), 
        location = ph_location_type(type="body")) %>%
      print('iris_presentation.pptx')
    

    您可以在此处阅读文档:https://davidgohel.github.io/officer/articles/offcran/powerpoint.html#ggplot-objects-1

    【讨论】:

    • 我实际上错过了一个情节可以直接使用并最终成为图像。但是很好,谢谢。我有想太多事情的倾向:-)
    • 没问题,请参阅davidgohel.github.io/officer/reference/ph_with.html 以获取带有ph_with 的支持对象的完整列表
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 2019-06-11
    • 2012-02-27
    • 2017-09-06
    • 1970-01-01
    • 2021-12-28
    相关资源
    最近更新 更多