Skip to contents

Creation of a box-and-whisker chart object that can be inserted in a 'Microsoft' document. Boxplot charts use the chartEx pipeline (Office 2016+); older versions of 'Microsoft Office' will display a fallback placeholder.

Data is in long format: one row per observation. Office computes quartiles and whiskers from the raw values; do not pre-aggregate.

Usage

ms_boxplotchart(
  data,
  x,
  y,
  quartile_method = c("exclusive", "inclusive"),
  show_mean_marker = TRUE,
  show_mean_line = FALSE,
  show_outliers = TRUE,
  show_inner_points = FALSE
)

Arguments

data

a data.frame.

x

category column name. Each unique value becomes one box.

y

numeric value column name (raw observations).

quartile_method

one of "exclusive" (default) or "inclusive". Affects how Q1/Q3 are computed when the count is even.

show_mean_marker

logical, draw the mean as a marker. Default TRUE.

show_mean_line

logical, draw a line connecting means across boxes. Default FALSE.

show_outliers

logical, plot outlier points. Default TRUE.

show_inner_points

logical, plot all non-outlier points. Default FALSE.

Value

An ms_chart object (subclass ms_boxplotchart).

Examples

library(officer)

set.seed(1)
dat <- data.frame(
  group = rep(c("A", "B", "C"), each = 20),
  value = c(rnorm(20, 0, 5), rnorm(20, 3, 7), rnorm(20, -2, 4))
)
bp <- ms_boxplotchart(dat, x = "group", y = "value")

doc <- read_pptx()
doc <- add_slide(doc)
#> Warning: Calling `add_slide()` without specifying a `layout` is deprecated.
#>  Please pass a `layout` or use `layout_default()` to set a default.
#>  => I will now continue with the former `layout` default "Title and Content" for backwards compatibility...
doc <- ph_with(doc, bp, location = ph_location_fullsize())
print(doc, target = tempfile(fileext = ".pptx"))