簡體   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