ms_paretochart: Pareto chart object

View source: R/ms_paretochart.R

ms_paretochartR Documentation

Pareto chart object

Description

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

Office draws columns sorted by descending count plus a cumulative line on a secondary percentage axis.

Two input modes are supported:

  • aggregate = TRUE (default): data is in long format (one row per observation) and Office counts occurrences of each x value. y is optional; when supplied, values are summed per category.

  • aggregate = FALSE: data is already aggregated (one row per category) and y is the count/value column.

Usage

ms_paretochart(data, x, y = NULL, aggregate = TRUE)

Arguments

data

a data.frame.

x

category column name.

y

optional numeric column. With aggregate=TRUE and y=NULL, each row counts as 1.

aggregate

logical, see Description. Default TRUE.

Value

An ms_chart object (subclass ms_paretochart).

See Also

chart_labels()

Other 'Office' chart objects: ms_areachart(), ms_barchart(), ms_boxplotchart(), ms_bubblechart(), ms_chart_combine(), ms_funnelchart(), ms_histogramchart(), ms_linechart(), ms_piechart(), ms_radarchart(), ms_scatterchart(), ms_stockchart(), ms_sunburstchart(), ms_treemapchart(), ms_waterfallchart()

Examples

library(officer)

set.seed(1)
dat <- data.frame(
  defect = sample(c("A", "B", "C", "D"), 50, replace = TRUE,
                  prob = c(0.5, 0.25, 0.15, 0.1))
)
pa <- ms_paretochart(dat, x = "defect")

doc <- read_pptx()
doc <- add_slide(doc)
doc <- ph_with(doc, pa, location = ph_location_fullsize())
print(doc, target = tempfile(fileext = ".pptx"))

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