OK
It turns out to be simple if you understand the syntax...
Let's take a simple ggplot for example:
require("officer")
require("rvg")
require("ggplot2")
gg <- ggplot(mtcars, aes(x = mpg , y = wt, colour = qsec)) + geom_point() + theme_minimal()
option 1:
Opening an existing presentation and insert a new object (while deleting the objects in the presentation):
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
option 2:
Opening an existing presentation and embed an object in existing slide without deleting the existing objects on the slide:
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
Joni