[英]Export R base graphics using rvg to PowerPoint
I am trying to use the officer package in order to produce a PowerPoint document that contains R base graphics, preferably not with fixed resolution, but rather as editable vector graphics.我正在尝试使用 package 官员来生成包含 R 基本图形的 PowerPoint 文档,最好不要使用固定分辨率,而是作为可编辑的矢量图形。 Here is what I have been trying, but the resulting PowerPoint document still lacks the diagram (the intermediate .dml
was created and contains some XML).这是我一直在尝试的,但生成的 PowerPoint 文档仍然缺少图表(中间.dml
已创建并包含一些 XML)。
library (officer)
library (rvg)
# write an R base graphics plot to "plot.dml"
dml_pptx ("plot.dml")
x = (-300:300)/100
plot (x,sin(x),type="l",col="blue")
dev.off ()
# create a PowerPoint document
doc = read_pptx ()
doc = add_slide (doc,layout ="Title and Content",master="Office Theme")
ph_with (doc,external_img (src="plot.dml"),location=ph_location_type(type="body"))
print (doc,"example.pptx")
When I instead generate the graphics file by jpeg ("plot.jpg")
and then include that file in the presentation, it works, but I'd like to avoid a fixed resolution and have the diagram editable in PowerPoint.当我改为通过jpeg ("plot.jpg")
生成图形文件,然后将该文件包含在演示文稿中时,它可以工作,但我想避免固定分辨率并让图表在 PowerPoint 中可编辑。
An alternative strategy might be the export
package,另一种策略可能是export
package,
library (export)
x = (-300:300)/100
plot (x,sin(x),type="l",col="blue")
graph2ppt (file="example2.pptx",width=6,height=6)
The latter works interactively, but fails in a script.后者以交互方式工作,但在脚本中失败。 What am I missing?我错过了什么?
Thanks in advance for your help.在此先感谢您的帮助。
HPF高功率滤波器
You need to use argument code
of function dml
and provide an expression containing your plot instructions:您需要使用 function dml
的参数code
并提供包含您的 plot 指令的表达式:
library(rvg)
library(officer)
library(magrittr)
read_pptx() %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with(dml(code = {
x = (-300:300)/100
plot (x,sin(x),type="l",col="blue")
}), location = ph_location_type(type = "body")) %>%
print(target = "demo_rvg.pptx")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.