body_add_chart: Add a chart to a Word document

View source: R/body_add_chart.R

body_add_chartR Documentation

Add a chart to a Word document

Description

Add a ms_chart to an rdocx object. The graphic will be inserted in an empty paragraph.

Usage

body_add_chart(x, chart, style = NULL, pos = "after", width = 5, height = 3)

Arguments

x

an rdocx object

chart

an ms_chart object.

style

paragraph style

pos

where to add the new element relative to the cursor, one of "after", "before", "on".

height, width

height and width in inches.

Value

An rdocx object.

See Also

ph_with.ms_chart()

Examples

library(officer)
my_barchart <- ms_barchart(data = browser_data,
  x = "browser", y = "value", group = "serie")
my_barchart <- chart_settings( my_barchart, grouping = "stacked",
  gap_width = 50, overlap = 100 )

doc <- read_docx()
doc <- body_add_chart(doc, chart = my_barchart, style = "centered")
print(doc, target = tempfile(fileext = ".docx"))

mschart documentation built on May 17, 2026, 1:09 a.m.