Export several plots from R into ppt

假如想象 提交于 2020-06-25 05:08:29

问题


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

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 .


回答1:


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" )



回答2:


The answer below is outdated, as ReporteRs has been removed from CRAN and is superseded by 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, e.g. to produce a presentation with 2 slides :

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) 



回答3:


eoffice may be another choice. with the command below:

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


来源:https://stackoverflow.com/questions/36545027/export-several-plots-from-r-into-ppt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!