簡體   English   中英

使用 rvg 將 R 基本圖形導出到 PowerPoint

[英]Export R base graphics using rvg to PowerPoint

我正在嘗試使用 package 官員來生成包含 R 基本圖形的 PowerPoint 文檔,最好不要使用固定分辨率,而是作為可編輯的矢量圖形。 這是我一直在嘗試的,但生成的 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")

當我改為通過jpeg ("plot.jpg")生成圖形文件,然后將該文件包含在演示文稿中時,它可以工作,但我想避免固定分辨率並讓圖表在 PowerPoint 中可編輯。

另一種策略可能是export package,

library (export)

x = (-300:300)/100
plot (x,sin(x),type="l",col="blue")

graph2ppt (file="example2.pptx",width=6,height=6)

后者以交互方式工作,但在腳本中失敗。 我錯過了什么?

在此先感謝您的幫助。

高功率濾波器

您需要使用 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.

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