簡體   English   中英

使用 R 包 OFFICER 和 RVG 將 plot 從 R 導出到 pptx 文件時無法指定幻燈片大小

[英]Unable to specify slide size when exporting a plot from R to a pptx file using R packages OFFICER and RVG

我在 R 中創建了一個 plot,並將其導出為矢量 object 在 powerpoint 幻燈片(pptx 文件)中,使用“rvg”和“officer”包(下面的代碼)

我想在代碼創建的 pptx 中定義幻燈片的尺寸(高度和寬度),但我看不到執行此操作的選項。 可以指定導出的 plot object 的大小,但不能指定 powerpoint 幻燈片大小的大小。

將 plot 從 R 導出到 pptx 文件時,是否可以定義 powerpoint 幻燈片的大小?

非常感謝您的建議/幫助

#EXAMPLE CODE
#IMPORT LIBRARIES
library(officer)
library(rvg)
#MAKE RANDOM DATA
x<-rnorm(50,1,10)
y<-rnorm(50,2,20)
#WRAP PLOT CODE IN A FUNCTION
plot.code<-function(){
  plot(x,y)
}
#CREATE AND EXPORT PPTX FILE
export.plot<-read_pptx()
export.plot <- add_slide(export.plot, "Title and Content", "Office Theme")
export.plot<-ph_with_vg(export.plot,code=plot.code(),type="body",height=10,width=10)
 #height and width in the above code define the size of the plot, not the slide
print(export.plot, target = "export.plot.pptx")

我有同樣的問題,還沒有找到一個明確的答案,但我確實想出了一個偽劣的解決方法。

  1. 打開 Powerpoint 並保存帶有所需大小的幻燈片的空演示文稿。
  2. 在 R 中,閱讀您剛剛創建的 powerpoint。
  3. 添加R中的內容
  4. 在 R 中保存 powerpoint。

這看起來像這樣,帶有以前創建manually_created.pptx

doc <- officer::read_pptx("manually_created.pptx") %>%
        # remove the empty slide
        officer::remove_slide(1)

doc %>% 
   # add a new slide to the powerpoint
   officer::add_slide("Title and Content", "Office Theme") %>% 
   # add plot to the slide
   officer::ph_with_vg(code = plot.code(), type = "body", height = 10, width = 10) %>%
   # save the powerpoint
   officer:::print.rpptx("manually_created.pptx")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM