# NOT RUN {
#START_TAG_TEST
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 )
#STOP_TAG_TEST
# }
Run the code above in your browser using DataCamp Workspace