简体   繁体   English

将几个图从 R 导出到 ppt

[英]Export several plots from R into ppt

I found a function here to create a ppt with a slide for a plot created in R. Here is the link to that function: R: Function to export currently active R plot to Powerpoint/Word/LibreOffice我在这里找到了一个函数,可以为在 R 中创建的绘图创建带有幻灯片的 ppt。这是该函数的链接: R:将当前活动的 R 绘图导出到 Powerpoint/Word/LibreOffice 的函数

I would like my program to add several slide (containing one plot each).我希望我的程序添加几张幻灯片(每个幻灯片包含一个图)。

I currently use : export2ppt(file="plot.pptx") But I can't figure out how I add a second plot to the same file .我目前使用: export2ppt(file="plot.pptx")但我不知道如何将第二个绘图添加到同一个文件中。

Try for example尝试例如

library(ReporteRs)
doc =pptx( ) # create pptx
doc=addSlide(doc,"Title and Content") # add slide
doc<-addTitle(doc,"first") # add title
fun_1<-function(){
  plot(mpg ~ wt,  data = mtcars)
}
doc <- addPlot(doc, fun= fun_1,vector.graphic =FALSE )  # add plot

doc=addSlide(doc,"Title and Content") # add slide
doc<-addTitle(doc,"Second") # add title

fun_2<-function(){
  plot(mpg ~ cyl,  data = mtcars)
}
doc <- addPlot(doc, fun= fun_2,vector.graphic =FALSE ) # add plot
writeDoc(doc, "r-2.pptx" )

The answer below is outdated, as ReporteRs has been removed from CRAN and is superseded by officer .下面的答案已过时,因为ReporteRs已从 CRAN 中删除并由officer取代。 I just made a new package export built on top of officer that easily allows one to export several graphs to a single Powerpoint presentation using the graph2ppt() command and the append=TRUE option, eg to produce a presentation with 2 slides :我刚刚创建了一个建立在officer之上的新包export ,它可以轻松地允许使用graph2ppt()命令和append=TRUE选项将多个图形导出到单个 Powerpoint 演示文稿,例如生成带有 2 张幻灯片的演示文稿:

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="plots.pptx", width=6, height=5) 
qplot(Sepal.Width, Petal.Length, data = iris, color = Species, 
      size = Petal.Width, alpha = I(0.7))     
graph2ppt(file="plots.pptx", width=6, height=5, append=TRUE) 

eoffice may be another choice. eoffice 可能是另一种选择。 with the command below:使用以下命令:

install.packages("eoffice")
topptx(file="plots.pptx", width=6, height=5,append=T)

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

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