ms_waterfallchart: Waterfall chart object

View source: R/ms_waterfallchart.R

ms_waterfallchartR Documentation

Waterfall chart object

Description

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

Each row is one bar. Positive values rise, negative values fall. Categories listed in subtotals are rendered as absolute totals (typical for "Start", intermediate totals, and "End" bars).

Usage

ms_waterfallchart(data, x, y, subtotals = NULL)

Arguments

data

a data.frame.

x

category column name.

y

numeric value column name. Signed values: positive = up, negative = down. For subtotal rows, the value should be the running total at that point.

subtotals

integer vector of 1-based row indices that should be rendered as subtotal/total bars. Defaults to none.

Value

An ms_chart object (subclass ms_waterfallchart).

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_paretochart(), ms_piechart(), ms_radarchart(), ms_scatterchart(), ms_stockchart(), ms_sunburstchart(), ms_treemapchart()

Examples

library(officer)

dat <- data.frame(
  step = c("Start", "Q1", "Q2", "Q3", "End"),
  amount = c(100, 30, -20, 40, 150),
  stringsAsFactors = FALSE
)
wf <- ms_waterfallchart(
  data = dat, x = "step", y = "amount",
  subtotals = c(1, 5)
)

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

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