Skip to contents

It lets R users create Microsoft Office charts from data, and then add title, legends, and annotations to the chart object.

The graph produced is a Microsoft graph, which means that it can be edited in your Microsoft software and that the underlying data are available.

The package will not allow you to make the same charts as with ggplot2. It allows only a subset of the charts possible with 'Office Chart'. The package is often used to industrialize graphs that are then consumed and annotated by non-R users.

The following chart types are available.

Classical charts (Office 2007+ DrawingML pipeline):

chartEx charts (Office 2016+ pipeline; older viewers show a placeholder):

Several classical chart types can be combined on a single chart, with an optional secondary axis (y or x), using ms_chart_combine().

These functions create a 'chart' object that can be customized:

You can add a chart into a slide in PowerPoint with function ph_with.ms_chart().

You can add a chart into a Word document with function body_add_chart().

You can add a chart into an Excel sheet with function sheet_add_drawing.ms_chart().

Series styling properties by chart type

Not all series styling properties have an effect on every chart type. A warning is emitted when a property is set on a chart type that does not support it.

Classical charts:

Propertybarlineareascatterstockradarbubblepie
fillxxxxxxxx
colourxxxxxxxx
symbolxxxx
sizexxxx
line_widthxxxxxxxx
line_stylexxxx
smoothxx
labels_fpxxxxxx

chartEx charts expose a narrower set of styling knobs, since most visual aspects are computed by Office from the data (bins, levels, connectors, ...). For these, prefer the chart-type-specific chart_settings() method when one is available (e.g. for pareto and boxplot: chart_settings(x, line = fp_border(...))).

Propertyboxplotfunnelhistogramparetosunbursttreemapwaterfall
fillxxxxxxx
colourxxxxxxx
labels_fpxxxxxxx

Two arguments often confused: asis and write_data

asis is a constructor argument (on ms_barchart(), ms_linechart() and most other classical constructors). It describes the input shape of the data frame:

  • asis = FALSE (default): long format, with a group column that splits the rows into series. mschart reshapes the data internally.

  • asis = TRUE: wide format, with one column per series. y accepts a vector of series column names.

write_data is an embed-time argument of sheet_add_drawing.ms_chart() for the Excel pipeline. It decides whether mschart writes the chart's data into the target sheet (TRUE, the default) or leaves you in charge of placing it via officer::sheet_write_data() (FALSE, recommended for non-trivial workbooks).

The two arguments are independent: a chart built with asis = TRUE can still be embedded with either write_data = TRUE or write_data = FALSE.

Author

Maintainer: David Gohel david.gohel@ardata.fr

Authors:

Other contributors:

  • ArData [copyright holder]

  • YouGov [funder]

  • Jan Marvin Garbuszus (support for openxlsx2 and combo charts) [contributor]

  • Stefan Moog moogs@gmx.de (support to set chart and plot area color and border, fix for line style none) [contributor]

  • Eli Daniels eli.daniels@ardata.fr [contributor]

  • Marlon Molina (added table feature) [contributor]

  • Rokas Klydzia (custom labels) [contributor]

  • David Camposeco david.camposeco.paulsen@gmail.com (chart_data_smooth function) [contributor]

  • Dan Joplin (fix scatter plot data structure) [contributor]