简体   繁体   English

官员包功能,用于将R图添加到演示文稿中

[英]officer package function for adding an R plot to a presentation

I am working on transfering my plots to a presentation using officer package in R. 我正在使用R中的officer包将我的情节转移到演示文稿中。

A ggplot can be transferred using the ph_with_gg() function but what is the function to transfer normal R plots? 可以使用ph_with_gg()函数传输ph_with_gg()但传输正常R图的功能是什么? I am not finding any such function in the package. 我没有在包中找到任何这样的功能。

These are few of the resouces that I am refering: 这些是我所指的资源中的一小部分:

officer CRAN package 官员CRAN包

PowerPoint presentations generation PowerPoint演示文稿生成

Your help will be appreciated! 我们将不胜感激!

Regards 问候

Save the plot you want to output as, say, a png file then use the ph_with_img function to place the image into your presentation. 保存要输出的绘图,例如png文件,然后使用ph_with_img函数将图像放入演示文稿中。

The on-line help for the Powerpoint component of officer shows how to do this - see https://davidgohel.github.io/officer/articles/powerpoint.html which you already referred to in your post. 官员的Powerpoint组件的在线帮助显示了如何执行此操作 - 请参阅您在帖子中提到的https://davidgohel.github.io/officer/articles/powerpoint.html

If you don't know how to save a plot as an image please see (for example) this thread: how to save a plot as image on the disk 如果您不知道如何将图表保存为图像,请参阅(例如)此主题: 如何将图表保存为磁盘上的图像

I have found a way of doing this using officer and rvg packages together. 我找到了一种使用officerrvg包一起做的方法。

rvg also allows us to edit our plots on the slides. rvg还允许我们在幻灯片上编辑我们的图。

The simple code to save a plot on slides is 在幻灯片上保存绘图的简单代码是

ppt <- ph_with_vg(ppt, code = plot(), type = "body")

If you would like to export R graphs to Powerpoint you can also use the wrapper package export built on top of officer that just came out on CRAN, see https://cran.r-project.org/web/packages/export/index.html and for demo https://github.com/tomwenseleers/export 如果您想将R图表导出到Powerpoint,您还可以使用在CRAN上出现的officer之上构建的包装程序包export ,请参阅https://cran.r-project.org/web/packages/export/index .html和演示https://github.com/tomwenseleers/export

Typical syntax is very easy and works for either base R, ggplot2 or lattice graphs, eg for a ggplot2 plot (but syntax is the same for base R plot, just call it after you made the plot): 典型的语法非常简单,适用于基本R,ggplot2或格子图,例如ggplot2图(但基本R图的语法相同,只需在制作图后调用它):

install.packages("export")
library(export)
library(ggplot2)
qplot(Sepal.Length, Petal.Length, data = iris, color = Species, 
      size = Petal.Width, alpha = I(0.7))     
graph2ppt(file="ggplot2_plot.pptx", width=6, height=5) 

You can also use it to export to Word, Excel, Latex or HTML and you can also use it to export statistical output of various R stats objects. 您还可以使用它导出到Word,Excel,Latex或HTML,还可以使用它导出各种R stats对象的统计输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM