Add a plot as a png image into an rdocx object.

body_add_plot(
  x,
  value,
  width = 6,
  height = 5,
  res = 300,
  style = "Normal",
  ...
)

Arguments

x

an rdocx object

value

plot instructions, see plot_instr().

width

height in inches

height

height in inches

res

resolution of the png image in ppi

style

paragraph style

...

Arguments to be passed to png function.

Examples

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") )