微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

军官:幻灯片以ggplot作为图像

如何解决军官:幻灯片以ggplot作为图像

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

现在,我要使用与图像相同的幻灯片 (例如,PNG,不可编辑)。我认为可以使用ph_with_gg(图,分辨率)等来实现,但这已被弃用。

可以将复制/粘贴作为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')

解决方法

在这种情况下,您无需致电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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。