addPlot: Add a plot into a document object

Description Usage Arguments Details Value See Also Examples

View source: R/addPlot.R

Description

Add a plot into a document object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
addPlot(doc, fun, pointsize = 12, vector.graphic = FALSE, ...)

## S3 method for class '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 class '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", ...)

Arguments

doc

document object

fun

plot function. The function will be executed to produce graphics. For grid or lattice or ggplot object, the function should just be print and an extra argument x should specify the object to plot. For traditionnal plots, the function should contain plot instructions. See examples.

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.

bookmark is a character vector specifying bookmark id to replace by the plot(s).
If provided, plot(s) will replace the paragraph that contains the bookmark.
If not provided, plot(s) will be added at the end of the document.

par.properties

paragraph formatting properties of the paragraph that contains plot(s). An object of class parProperties

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.

Details

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.

Value

a document object

See Also

docx, pptx

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
is_sunos <- tolower(Sys.info()[["sysname"]]) == "sunos"

options( "ReporteRs-fontsize" = 11 )


if( check_valid_java_version() ){
# 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" )

}


if( check_valid_java_version() ){
# 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" )

}

davidgohel/ReporteRs documentation built on Dec. 4, 2018, 5:10 p.m.