Add a plot as a png image into an rdocx object.
body_add_plot(
x,
value,
width = 6,
height = 5,
res = 300,
style = "Normal",
pos = "after",
...
)
an rdocx object
plot instructions, see plot_instr()
.
height in inches
height in inches
resolution of the png image in ppi
paragraph style
where to add the new element relative to the cursor, one of "after", "before", "on".
Arguments to be passed to png function.
Other functions for adding content:
body_add_blocks()
,
body_add_break()
,
body_add_caption()
,
body_add_docx()
,
body_add_fpar()
,
body_add_gg()
,
body_add_img()
,
body_add_par()
,
body_add_table()
,
body_add_toc()
doc <- read_docx()
if (capabilities(what = "png")) {
doc <- body_add_plot(doc,
value = plot_instr(
code = {
barplot(1:5, col = 2:6)
}
),
style = "centered"
)
}
print(doc, target = tempfile(fileext = ".docx"))