addPlot.bsdoc

0th

Percentile

Add a plot into an bsdoc object

Add a plot into the bsdoc object.

Usage
## S3 method for class 'bsdoc':
addPlot(doc, fun, pointsize = getOption("ReporteRs-fontsize"),
  vector.graphic = T, width = 6, height = 6,
  fontname = getOption("ReporteRs-default-font"),
  par.properties = parCenter(padding = 5), ...)
Arguments
doc
Object of class bsdoc where paragraph has to be added
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 pl
pointsize
the default pointsize of plotted text in pixels, default to 12.
vector.graphic
logical scalar, default to FALSE. If TRUE, vector graphics are produced instead of PNG images. If TRUE, vector graphics are RaphaelJS instructions(transformed as SVG).
width
plot width in inches (default value is 6).
height
plot height in inches (default value is 6).
fontname
the default font family to use, default to getOption("ReporteRs-default-font").
par.properties
paragraph formatting properties of the paragraph that contains plot(s). An object of class parProperties
...
arguments for fun.
Value

  • an object of class bsdoc.

See Also

bsdoc, addPlot , add.plot.interactivity

Aliases
  • addPlot.bsdoc
Examples
doc.filename = "addPlot_bsdoc/example.html"

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

doc = bsdoc( )

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
if( requireNamespace("ggplot2", quietly = TRUE) ){

  # create a ggplot2 plot
  myplot = ggplot2::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 )
}


doc = addTitle( doc, "Title example 3", level = 1 )
###########################################################
# Create lm.D9, a lm object
ctl = c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt = c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group = gl(2, 10, 20, labels = c("Ctl","Trt"))
weight = c(ctl, trt)
lm.D9 = lm(weight ~ group)

# add the 6 plots into the document
doc = addPlot( doc, plot, x = lm.D9, width = 6, height = 7 )

# Write the object
writeDoc( doc, file = doc.filename )
Documentation reproduced from package ReporteRs, version 0.7.7, License: GPL-3

Community examples

Looks like there are no examples yet.