[英]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")
我有同样的问题,还没有找到一个明确的答案,但我确实想出了一个伪劣的解决方法。
这看起来像这样,带有以前创建的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.