r - 为什么我不能将网格中的一组绘图发送给带有官员的PowerPoint?

时间:2018-01-23 17:28:42

标签: r gridextra officer

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

doc_parse_raw中的错误(x,encoding = encoding,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()

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

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

2 个答案:

答案 0 :(得分:2)

使用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()

答案 1 :(得分: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()