
Last chance! 50% off unlimited learning
Sale ends in
Add a plot into a document object
addPlot(doc, fun, pointsize = 12, vector.graphic = F,
...)
document object
plot function
logical scalar, if TRUE, vector graphics are produced instead of PNG images.
SVG will be produced for html
objects and
DrawingML instructions for docx
and pptx
objects.
DrawingML instructions offer advantage to provide editable graphics (forms and texts colors, texts contents, moving and resizing is disabled).
the default pointsize of plotted text in pixels, default to 12.
further arguments passed to or from other methods..
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. See examples for more details.
If document is a pptx or html document, vector graphics will always be displayed. Don't use vector graphics if document is a docx and MS Word version used to open the document is 2007.
docx
, addPlot.docx
,
pptx
, addPlot.pptx
,
html
, addPlot.html
# NOT RUN {
# Add a base plot
doc = addPlot( doc = doc, fun = plot
, x = rnorm( 100 )
, y = rnorm (100 )
, main = "base plot main title"
)
## Add a ggplot2
myplot = qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7))
doc = addPlot( doc = doc
, fun = print
, x = myplot #this argument MUST be named, print is expecting argument 'x'
)
## Add a ggplot2 and another plot
require(ggplot2)
doc = addPlot( doc = doc
, fun = function(){
print( qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7)) )
plot(x = rnorm( 100 ), y = rnorm (100 ), main = "base plot main title")
}
)
# }
Run the code above in your browser using DataLab