ReporteRs (version 0.6.0)

addPlot.docx: Add a plot into a docx object

Description

Add a plot into the docx object.

Usage

# S3 method for docx
addPlot(doc, fun, pointsize = getOption("ReporteRs-fontsize"),
  vector.graphic = F, width = 6, height = 6,
  fontname = getOption("ReporteRs-default-font"), editable = TRUE, bookmark,
  par.properties = parProperties(text.align = "center", padding = 5), ...)

Arguments

doc

the docx to use

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.

width

plot width in inches (default value is 6).

height

plot height in inches (default value is 6).

vector.graphic

logical scalar, default to FALSE.

DrawingML instructions cannot be read by MS Word 2007.

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. See 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

pointsize

the default pointsize of plotted text in pixels, default to getOption("ReporteRs-fontsize").

fontname

the default font family to use, default to getOption("ReporteRs-default-font").

editable

logical value - if TRUE vector graphics elements (points, text, etc.) are editable.

...

arguments for fun.

Value

an object of class docx.

See Also

docx, addPlot, bookmark.

Examples

Run this code
# NOT RUN {
#START_TAG_TEST
doc.filename = "addPlot_example.docx"

# set default font size to 10
options( "ReporteRs-fontsize" = 10 )

doc = docx( )

doc = addTitle( doc, "Title example 1", level = 1 )
# Add a base plot
# set vector.graphic to FALSE if Word version
#   used to read the file is <= 2007
doc = addPlot( doc, fun = plot
  , x = rnorm( 100 ), y = rnorm (100 )
  , main = "base plot main title"
  , vector.graphic = TRUE
  , width = 5, height = 7
  , par.properties = parProperties(text.align = "left")
)


doc = addTitle( doc, "Title example 2", level = 1 )
# load ggplot2
require( ggplot2 )

# create a ggplot2 plot
myplot = qplot(Sepal.Length, Petal.Length, data = iris
  , color = Species, size = Petal.Width, alpha = I(0.7) )

# Add myplot into object doc
#   myplot is assigned to argument 'x' because function 'print' on ggplot
#   objects is expecting argument 'x'.
doc = addPlot( doc = doc, fun = print, x = myplot )

# Write the object
writeDoc( doc, file = doc.filename )
#STOP_TAG_TEST
# }

Run the code above in your browser using DataCamp Workspace