View source: R/waterfall_chart.R
| waterfall_chart | R Documentation |
A waterfall chart shows how an initial value is built up or eroded by a series of positive and negative contributions to reach a final total. Each bar starts exactly where the previous one ended, making cumulative effects immediately visible. It is the standard chart for P&L decomposition, budget variance analysis, and any "what changed and why" narrative.
Hovering over a bar shows a tooltip with the label, the delta value, and the running total at that point.
waterfall_chart(
data,
x,
y,
measure = NULL,
positiveColor = "#4CAF50",
negativeColor = "#F44336",
totalColor = "#5C85D6",
connector = TRUE,
connectorColor = "#aaaaaa",
showLabels = TRUE,
labelFontSize = 10,
title = NULL,
titleFontSize = 16,
xtitle = NULL,
xtitleFontSize = 13,
ytitle = NULL,
ytitleFontSize = 13,
xFontSize = 11,
yFontSize = 11,
opacity = 1,
font = "Verdana, Geneva, Tahoma, sans-serif",
bgcol = "white",
axisCol = "black",
width = NULL,
height = NULL
)
data |
The data frame containing the variables to consider. |
x |
The name of the column containing category labels. |
y |
The name of the column containing the delta values (positive for increases, negative for decreases). |
measure |
Optional. The name of a column that classifies each row as
|
positiveColor |
Fill color for bars representing an increase.
Defaults to |
negativeColor |
Fill color for bars representing a decrease.
Defaults to |
totalColor |
Fill color for |
connector |
Logical. Whether to draw dashed connector lines between
consecutive bars. Defaults to |
connectorColor |
Color of the connector lines. Defaults to
|
showLabels |
Logical. Whether to display the delta value above or
below each bar. Defaults to |
labelFontSize |
Font size of the bar value labels. Defaults to
|
title |
Optional. Title of the chart. |
titleFontSize |
Font size of the chart title. Defaults to |
xtitle |
Optional. Title of the x-axis. |
xtitleFontSize |
Font size of the x-axis title. Defaults to |
ytitle |
Optional. Title of the y-axis. |
ytitleFontSize |
Font size of the y-axis title. Defaults to |
xFontSize |
Font size of the x-axis tick labels. Defaults to |
yFontSize |
Font size of the y-axis tick labels. Defaults to |
opacity |
Opacity of the bars (0 to 1). Defaults to |
font |
The font family used for all text. Defaults to
|
bgcol |
Background color of the SVG. Defaults to |
axisCol |
Color of axis lines, ticks, and labels. Defaults to
|
width |
Optional. The width of the SVG output. |
height |
Optional. The height of the SVG output. |
An interactive SVG waterfall chart.
# P&L bridge: from revenue down to net income
pnl <- data.frame(
label = c("Revenue", "COGS", "Gross Profit",
"R&D", "S&M", "G&A", "Operating Income"),
value = c(1200, -450, 750, -120, -90, -60, 480),
measure = c("relative", "relative", "total",
"relative", "relative", "relative", "total")
)
waterfall_chart(
data = pnl,
x = "label",
y = "value",
measure = "measure",
title = "P&L bridge",
ytitle = "USD thousands"
)
# Monthly cash flow
cashflow <- data.frame(
month = c("Jan", "Feb", "Mar", "Apr", "May", "Jun"),
delta = c(120, -30, 80, -60, 95, -20)
)
waterfall_chart(
data = cashflow,
x = "month",
y = "delta",
title = "Monthly cash flow",
ytitle = "USD thousands",
positiveColor = "steelblue",
negativeColor = "tomato"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.