3

我已经使用 gridextra 创建了一个 qicharts2 绘图网格,但是当我尝试使用官员将其发送到 PowerPoint 时,我收到了这个错误。

doc_parse_raw 中的错误(x,编码 = 编码,base_url = base_url,as_html = as_html,:StartTag:无效元素名称 [68]

这是我的代码:

library(qicharts2)
library(gridExtra)
library(officer)
library(rvg)



#24 random numbers from a normal distribution for example.
y1 <- rnorm(24)
y2 <- rnorm(24)

yC1 <- qic(y1)
yC2 <- qic(y2)

grid <- grid.arrange(yC1,yC2)


filename <- "C:\\Desktop\\MyCharts.pptx"


read_pptx(filename) %>% 

  add_slide(layout = "Title and Content", master = "Office Theme") %>% 
  ph_with_vg(code = print(grid), type = "body") %>% 
  print(target = filename) %>% 
  invisible()

非常感谢大家就如何改进我的问题提出建议。

任何帮助进一步帮助大大收到

4

2 回答 2

3

使用时grid.arrange,您正在绘图,打印方法在这里没有用(print(grid)对图形设备没有影响)。以下正在使用grid.arrange

library(qicharts2)
library(gridExtra)
library(officer)
library(rvg)
library(magrittr)

#24 random numbers from a normal distribution for example.
y1 <- rnorm(24)
y2 <- rnorm(24)

yC1 <- qic(y1)
yC2 <- qic(y2)

read_pptx() %>% 
  add_slide(layout = "Title and Content", master = "Office Theme") %>% 
  ph_with_vg(code = grid.arrange(yC1,yC2), type = "body") %>% 
  print(target = "filename.pptx") %>% 
  browseURL()

编辑> rvg = 0.2.4:您必须使用以下dml功能:

read_pptx() %>% 
  add_slide(layout = "Title and Content", master = "Office Theme") %>% 
  ph_with(value = dml(grid.arrange(yC1,yC2)), location = ph_location_type(type = "body")) %>% 
  print(target = "filename.pptx") %>% 
  browseURL()
于 2018-01-29T12:08:14.437 回答
0

添加情节而不是打印对我有用。grid.arrange 中有一些错误,但如果它通过 plot() 它可以工作。这个特定示例的工作方式与之前的答案一样,但更复杂的是多个 grobs 和文本框不是。

read_pptx() %>% 
  add_slide(layout = "Title and Content", master = "Office Theme") %>% 
  ph_with(value = dml(code=plot(grid.arrange(yC1,yC2))),
          location = ph_location_type(type = "body")) %>% 
  print(target = "filename.pptx") %>% 
  browseURL()
于 2021-02-03T00:06:06.190 回答