Add a plot into a document object
addPlot(doc, fun, pointsize = 12, vector.graphic = FALSE, ...) # S3 method for docx addPlot(doc, fun, pointsize = getOption("ReporteRs-fontsize"), vector.graphic = FALSE, width = 6, height = 6, fontname_serif = "Times New Roman", fontname_sans = "Calibri", fontname_mono = "Courier New", fontname_symbol = "Symbol", editable = TRUE, bookmark, par.properties = parProperties(text.align = "center", padding = 5), bg = "transparent", ...) # S3 method for pptx addPlot(doc, fun, pointsize = 11, vector.graphic = TRUE, fontname_serif = "Times New Roman", fontname_sans = "Calibri", fontname_mono = "Courier New", fontname_symbol = "Symbol", editable = TRUE, offx, offy, width, height, bg = "transparent", ...)
doc | document object |
---|---|
fun | plot function. The function will be executed to produce graphics.
For |
pointsize | the default pointsize of plotted text in pixels, default to 12 pixels. |
vector.graphic | logical scalar, if TRUE, vector graphics are produced instead, PNG images if FALSE. |
... | further arguments passed to or from other methods. See details. |
width | plot width in inches (default value is 6). |
height | plot height in inches (default value is 6). |
fontname_serif, fontname_sans, fontname_mono, fontname_symbol | font names for font faces. Use fonts available on operating system. |
editable | logical value - if TRUE vector graphics elements (points, text, etc.) are editable. |
bookmark | id of the Word bookmark to replace by the plot. optional.
|
par.properties | paragraph formatting properties of the paragraph that contains plot(s).
An object of class |
bg | the initial background colour. |
offx, offy | optional. x and y position of the shape (left top position of the bounding box) in inches. See details. |
a document object
Plot parameters are specified with the ...
argument.
However, the most convenient usage is to wrap the plot code
into a function whose parameters will be specified as '...'.
If you want to add ggplot2 or lattice plot, use print
function.
vector.graphic
: DrawingML instructions will be produced
for docx
and pptx
objects.
Don't use vector graphics if document is a docx and MS Word version
used to open the document is 2007.
When document is a pptx
object, two positioning methods are available.
If arguments offx, offy, width, height are missing, position and dimensions
will be defined by the width and height of the next available shape of the slide. This
dimensions can be defined in the layout of the PowerPoint template used to create
the pptx
object.
If arguments offx, offy, width, height are provided, they become position and dimensions of the new shape.
is_sunos <- tolower(Sys.info()[["sysname"]]) == "sunos" options( "ReporteRs-fontsize" = 11 ) # plot example for docx -----doc = docx( ) doc = addPlot( doc, fun = function() barplot( 1:6, col = 2:7), vector.graphic = TRUE, width = 5, height = 7, par.properties = parProperties(text.align = "center") ) writeDoc( doc, file = "ex_plot.docx" )# plot example for pptx -----doc = pptx( ) doc = addSlide( doc, slide.layout = "Title and Content" ) doc = addPlot( doc, fun = function() barplot( 1:6, col = 2:7), vector.graphic = TRUE, width = 5, height = 4 ) if( !is_sunos ){ doc = addPlot( doc, fun = function() barplot( 1:6, col = 2:7), vector.graphic = FALSE, offx = 7, offy = 0, width = 3, height = 2 ) } writeDoc( doc, file = "ex_plot.pptx" )