Fill an Entire PowerPoint Slide with an R Plot?

北慕城南 提交于 2019-12-11 06:09:29

问题


How can I fill an entire PowerPoint slide with an R plot? I'd like to use vector graphics (otherwise screenshot and crop would be a solution). I'd also like to avoid manual touches.

The following code (grabbed from this post) does a perfectly fine job of filling the "Content" of a "Title and Content" slide.

library( ReporteRs )
require( ggplot2 )
mydoc = pptx( )
mydoc = addSlide( mydoc, slide.layout = "Title and Content" )
mydoc = addTitle( mydoc, "Plot examples" )
myplot = qplot(Sepal.Length, Petal.Length
               , data = iris, color = Species
               , size = Petal.Width, alpha = I(0.7)
)
mydoc = addPlot( mydoc, function( ) print( myplot ), vector.graphic=TRUE)
writeDoc( mydoc, file = "test plot.pptx" )

I thought I might be able to fill an entire slide using the following code:

library( ReporteRs )
require( ggplot2 )
mydoc = pptx( )
mydoc = addSlide( mydoc, slide.layout = "Blank" )
#mydoc = addTitle( mydoc, "Plot examples" )
myplot = qplot(Sepal.Length, Petal.Length
               , data = iris, color = Species
               , size = Petal.Width, alpha = I(0.7)
)
mydoc = addPlot( mydoc, function( ) print( myplot ), vector.graphic=TRUE)
writeDoc( mydoc, file = "test plot.pptx" )

But, i get the error message:

Error in next_shape_pos(doc) : 
  shape of type 'plot' has no more room left to be displayed in the layout

I think there may be a solution where I create new PowerPoint slide layout with content filling the entire slide and then save as a PowerPoint template? But I'm not very familiar with this stuff and am starting to feel like I'm missing something obvious.


回答1:


You have effectively answered your own question. You need to create a template in PowerPoint with a new layout that has a single content placeholder filling the slide.

In PowerPoint 2016, you would do the following:

  • File -> New -> Blank presentation
  • Delete the first (and only) slide
  • View -> Slide Master
  • Slide Master -> Insert Layout
  • Delete all existing placeholders on this layout
  • Slide Master -> Insert Placeholder -> Content
  • Resize the new placeholder to fill the slide
  • Right click on the layout in the left-hand layout list
  • Rename layout
  • "Full page content"
  • File -> Save as -> Browse
  • Choose a location and name for the presentation template (e.g. "Documents/R/BlankPresentation.pptx")

Now run the following R code:

library(ReporteRs)
library(ggplot2)
mydoc <- pptx(template = "path to presentation template saved above")
mydoc <- addSlide(mydoc, slide.layout = "Full page content")
myplot <- qplot(
  Sepal.Length,
  Petal.Length,
  data = iris,
  color = Species,
  size = Petal.Width,
  alpha = 0.7
)
mydoc <- addPlot(mydoc, function() print(myplot), vector.graphic = TRUE)
writeDoc(mydoc, file = "test plot.pptx")


来源:https://stackoverflow.com/questions/42892913/fill-an-entire-powerpoint-slide-with-an-r-plot

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