Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

body_add_chart

add chart into a Word document


Description

add a ms_chart into 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.

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

Chart Generation for 'Microsoft Word' and 'Microsoft PowerPoint' Documents

v0.3.0
MIT + file LICENSE
Authors
David Gohel [aut, cre], ArData [cph], YouGov [fnd], Rokas Klydzia [ctb] (custom labels), David Camposeco [ctb] (chart_data_smooth function), Dan Joplin [ctb] (fix scatter plot data structure)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.