Add a plot to the current slide of an existing pptx
object.
# S3 method for pptx
addPlot(doc, fun, pointsize = 11, vector.graphic = TRUE,
fontname = getOption("ReporteRs-default-font"), editable = TRUE, ...)
the pptx
to use
plot function
the default pointsize of plotted text, interpreted as big points (1/72 inch) at res ppi.
logical scalar, default to TRUE. If TRUE, vector graphics are produced instead of PNG images. Vector graphics in pptx document are DrawingML instructions.
the default font family to use, default to getOption("ReporteRs-default-font").
logical value - if TRUE vector graphics elements (points, texts, etc.) are editable.
arguments for fun
.
an object of class "pptx"
.
Width and height can't be controled here. They are defined by the width and height of the shape that will contain the graphics.
This dimensions can be defined in the layout of the
PowerPoint template used to create the pptx
object.
# NOT RUN {
#START_TAG_TEST
require( ggplot2 )
# Create a new document
doc = pptx( title = "title" )
# add a slide with layout "Title and Content" then add plot
doc = addSlide( doc, slide.layout = "Title and Content" )
doc = addTitle( doc, "base plot" )
# Add a base plot
doc = addPlot( doc, fun = plot
, x = rnorm( 100 )
, y = rnorm (100 )
, main = "base plot main title"
)
# add a slide with layout "Two Content" then add 2 plots
doc = addSlide( doc, slide.layout = "Two Content" )
doc = addTitle( doc, "2 ggplot2 examples" )
doc = addPlot( doc
, function(){
print( qplot(Sepal.Length, Petal.Length, data = iris, color = Species
, size = Petal.Width, alpha = I(0.7)) )
}
)
myplot = qplot(Sepal.Length, Petal.Length, data = iris, color = Species
, size = Petal.Width, alpha = I(0.7))
doc = addPlot( doc
, print
, x = myplot #this argument MUST be named, print is expecting argument 'x'
, vector.graphic = FALSE
)
# Write the object in file "addPlot_example.pptx"
writeDoc( doc, "addPlot_example.pptx" )
#STOP_TAG_TEST
# }
Run the code above in your browser using DataLab