繁体   English   中英

使用“ph_with_vg_at”R 函数将图形嵌入到现有的 pptx 幻灯片中

[英]Embed a graph into an existing pptx slide using the "ph_with_vg_at" R function

我有一个 R 应用程序,它通过 Office 工具 (pptx) 构建大量客户端可编辑图表。 我尝试以矢量格式将 ggplot 图嵌入到现有的 slied 中。 我使用 ph_with_vg_at 函数将图形导出到 pptx。 关键是将图形导出到 pptx 会删除幻灯片上已经存在的所有元素。 那么如何将图形导出到幻灯片而不删除幻灯片上的信息?

谢谢乔尼

好的

如果你理解语法,结果会很简单......让我们以一个简单的 ggplot 为例:

require("officer")
require("rvg")
require("ggplot2")

gg <- ggplot(mtcars, aes(x = mpg , y = wt, colour = qsec)) + geom_point() + theme_minimal()

选项 1:打开现有演示文稿并插入新对象(同时删除演示文稿中的对象):

doc <- read_pptx() # Creat a virtual new pptx and set the ggplot as a new slide
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with_vg(doc, code =print(gg),type = "body")


print(doc, target = "G:/Layers/gg.pptx") # Exporting to Exist pptx file

选项 2:打开现有演示文稿并在现有幻灯片中嵌入对象而不删除幻灯片上的现有对象:

doc <- read_pptx(path = "G:/Layers/template.pptx")# Opening an Exist pptx file


doc <- on_slide( doc, index = 1)# Embedding of the ggplot into the slide
doc <- ph_with_vg_at(doc, ggobj = gg, left=0.1, top=0.1, width=7.5, height=6)

   print(doc, target = "G:/Layers/template.pptx")# Exporting to Exist pptx file

乔尼

试试eoffice:

install.packages("eoffice")
library(eoffice)
gg <- ggplot(mtcars, aes(x = mpg , y = wt, colour = qsec)) + geom_point() + theme_minimal()
topptx(gg,file="gg.pptx")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM