与军官一起从GGPLOT出口多句话
不知何故,我无法使用官员
软件包将包含三个子图的绘图正确导出。我将最多的MWE具有相同但不同的数据产生我要导出的绘图,
library(fpp3)
library(officer)
library(rvg)
p1 <- global_economy %>%
filter(Code == "CAF") %>%
gg_tsdisplay(difference(Exports), plot_type='partial')
#PPT
p_dml <- rvg::dml(ggobj = p1, editable = F)
my_pres <- read_pptx("...path/presentation.pptx")
my_pres <- add_slide(my_pres,layout = "Headline 1-zeilig", master = "Master-Design") #should be adjusted
my_pres<- ph_with(my_pres, value = p_dml , location = ph_location_fullsize())
print(my_pres, target = "...path/presentation.pptx")
中产生的图表。
,但在最终的PowerPoint中,只显示右下图,而不是所有三个图。
somehow I am not able to properly export a plot containing three subplots into my PowerPoint with the officer
package. I will most an MWE with the same but different data that produces the plot that I want to export
library(fpp3)
library(officer)
library(rvg)
p1 <- global_economy %>%
filter(Code == "CAF") %>%
gg_tsdisplay(difference(Exports), plot_type='partial')
#PPT
p_dml <- rvg::dml(ggobj = p1, editable = F)
my_pres <- read_pptx("...path/presentation.pptx")
my_pres <- add_slide(my_pres,layout = "Headline 1-zeilig", master = "Master-Design") #should be adjusted
my_pres<- ph_with(my_pres, value = p_dml , location = ph_location_fullsize())
print(my_pres, target = "...path/presentation.pptx")
This is the graph that I am producing inside R:
But in the final PowerPoint only the lower right figure is displayed and not all three graphs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,
gg_tsdisplay返回的对象
不是ggplot
对象,而是ggplot对象列表。结果,仅此列表的最后一个元素被导出到PPTX,或者在第一个转换为DML对象的情况下,您会遇到错误。一种可能的修复方法是使用
patchwork
软件包构建多图,作为副作用将“将”绘图列表“转换”到GGPLOT对象。这样做之后,无论是ggplot
对象还是dml
对象,您都可以轻松地导出到PPTX。在下面的代码中,我使用patchwork :: wrap_plots
并使用design
参数来模仿您的多图的布局:The issue is that the object returned by
gg_tsdisplay
is not aggplot
object but a list of ggplot objects instead. As a consequence only the last element of this list is exported to the pptx or you get an error in the case where your first convert to a dml object.One possible fix would be to build your multi plot using the
patchwork
package which as a side effect will "convert" the list of plots to a ggplot object. After doing so you could easily export to pptx whether as aggplot
object or as andml
object. In my code below I usepatchwork::wrap_plots
and use thedesign
argument to mimic the layout of your multi plot: