【发布时间】: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')
【问题讨论】: