Description Usage Arguments Details Examples
Insert a plot into the Docx
object.
1 2 3 |
doc |
the |
fun |
plot function |
width |
plot width in inches (default value is 7). |
height |
plot height in inches (default value is 6). |
legend |
optional character string, legend to add below the plot |
stylename |
name of the style to apply to the legend text (default value is "PlotReference" - a style available in the default base document.). |
bookmark |
a character value ; id of the Word bookmark to replace by the plot. optional |
... |
arguments for |
This function work with base R graphics. 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.
bookmark
: a character vector specifying bookmark id to replace by the table.
If provided, table will replace the paragraph that contains the bookmark.
If not provided, table will be added at the end of the document.
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 | docx.file = "Hello_Word.docx"
require(R2DOCX)
# Create a new document
doc <- new("Docx", title = "title" )
# Add a base plot
doc = addPlot( doc
, fun = plot
, x = rnorm( 100 )
, y = rnorm (100 )
, main = "base plot main title"
)
## Add a ggplot2
## Not run:
require(ggplot2)
# method 1 :
doc = addPlot( doc
, function(){
print( qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7)) )
}
, width = 8, height = 7, legend="graph example"
, stylename = "PlotReference"
)
# method 2 :
myplot = qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Petal.Width, alpha = I(0.7))
doc = addPlot( doc
, print
, width = 8, height = 7, legend="graph example"
, stylename = "PlotReference"
, x = myplot #this argument MUST be named, print is expecting argument 'x'
)
writeDoc( doc, docx.file )
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.