Title: | Waterfall Charts |
---|---|
Description: | Provides support for creating waterfall charts in R using both traditional base and lattice graphics. |
Authors: | James P. Howard, II [aut, cre] |
Maintainer: | "James P. Howard, II" <[email protected]> |
License: | BSD_2_clause + file LICENSE |
Version: | 1.0.2 |
Built: | 2025-03-10 04:03:37 UTC |
Source: | https://github.com/k3jph/waterfall |
Create waterfall or "McKinsey" charts
This package provides support for creating waterfall charts in R using both traditional base and lattice graphics.
James P. Howard, II <[email protected]>
This dataset provides the sample business-adjusted risk from Security Metrics to illustrate non-financial waterfall charts.
data(jaquith)
data(jaquith)
A data frame with 9 rows and 2 columns.
[,1] | factor | character | Factor label |
[,2] | score | numeric | Relative score |
The dataset represents a sample business-adjusted risk calculation.
Andrew Jaquith, Security Metrics: Replacing Fear, Uncertainty, and Doubt (Boston: Addison-Wesley Professional, 2007), 170-171.
This dataset provides the sample financial data used in The McKinsey Way to illustrate financial waterfall charts.
data(rasiel)
data(rasiel)
A data frame with 5 rows and 3 columns.
[,1] | label | character | Column label |
[,2] | value | numeric | Column height |
[,3] | subtotal | character | Group and subtotal labels |
The dataset represents a profit and loss statement for the fictional ACME Widget Corporation for 1998.
Ethan M. Rasiel, The McKinsey Way: Using the Techniques of the World's Top Strategic Consultants to Help You and Your Business (New York: McGraw-Hill, 1999), 115-116.
Creates a waterfall chart using Lattice
waterfallchart(x, data = NULL, groups = NULL, horizontal = FALSE, panel = panel.waterfallchart, prepanel = prepanel.waterfallchart, summaryname = "Total", box.ratio = 2, origin = 0, level.lines = TRUE, ...)
waterfallchart(x, data = NULL, groups = NULL, horizontal = FALSE, panel = panel.waterfallchart, prepanel = prepanel.waterfallchart, summaryname = "Total", box.ratio = 2, origin = 0, level.lines = TRUE, ...)
x |
a formula describing the form of conditioning plot. The formula is generally of the form 'y ~ x | g1 * g2 * ...', indicating that plots of 'y' (on the y axis) versus 'x' (on the x axis) should be produced conditional on the variables 'g1, g2, ...'. However, the conditioning variables 'g1,g2,...' may be omitted. |
data |
a data frame containing values (or more precisely, anything that is a valid 'envir' argument in 'eval', e.g., a list or an environment) for any variables in the formula, as well as 'groups' and 'subset' if applicable. If not found in 'data', or if 'data' is unspecified, the variables are looked for in the environment of the formula. |
groups |
a vector expected to act as a grouping variable within each panel, typically used to distinguish different groups by varying graphical parameters like color and line type. Unlike with the barchart function, groups specifies where subtotals columns, should appear. There is a subtotal created for each group specified. If no groups are given, a summary column is still reported. |
horizontal |
This argument is used to process the arguments to these high level functions, but more importantly, it is passed as an argument to the panel function, which is supposed to use it as appropriate. |
panel |
This draws the actual plot after bwplot has done the difficult work of processing the formula. |
prepanel |
This function returns the bwplot information on the number of columns to display and where to place labels. |
summaryname |
name of the summary column, usually "Total" |
box.ratio |
specifies the ratio of the width of the rectangles to the interrectangle space. |
origin |
initial offset relative to the x axis. The value serves as the logical starting point for the first column and any summary column. Defaults to 0. |
level.lines |
if FALSE, the lines connecting adjacent boxes are ommitted from the display. |
... |
further arguments. |
This function closely mimics the barchart interface, but provides a type of chart called a waterfall plot, showing how multiple subvalues contribute to a total sum.
The bulk of the work is actually processed in bwplot which defines where tickmarks and other information outside the plot itself are placed. Only a formula method is provided.
Matrix and vector interfaces are not provided because mimicing the behavior of barchart for those interfaces produces unintellible and undefined graphic output.
Andrew Jaquith, Security Metrics: Replacing Fear, Uncertainty, and Doubt (Boston: Addison-Wesley Professional, 2007), 170-172.
Ethan M. Rasiel, The McKinsey Way: Using the Techniques of the World's Top Strategic Consultants to Help You and Your Business (New York: McGraw-Hill, 1999), 113-118.
data(rasiel) data(jaquith) waterfallchart(value~label, data=rasiel, groups=rasiel$subtotal) waterfallchart(factor~score, data=jaquith)
data(rasiel) data(jaquith) waterfallchart(value~label, data=rasiel, groups=rasiel$subtotal) waterfallchart(factor~score, data=jaquith)
Creates a waterfall plot with vertical or horizontal bars.
waterfallplot(height, width = 1, space = NULL, names.arg = NULL, horiz = FALSE, density = NULL, angle = 45, col = NULL, border = par("fg"), main = NA, sub = NA, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, xpd = TRUE, axes = TRUE, axisnames = TRUE, cex.axis = par("cex.axis"), cex.names = par("cex.axis"), plot = TRUE, axis.lty = 0, offset = 0, add = FALSE, summary = FALSE, rev = FALSE, level.lines = TRUE, ...)
waterfallplot(height, width = 1, space = NULL, names.arg = NULL, horiz = FALSE, density = NULL, angle = 45, col = NULL, border = par("fg"), main = NA, sub = NA, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, xpd = TRUE, axes = TRUE, axisnames = TRUE, cex.axis = par("cex.axis"), cex.names = par("cex.axis"), plot = TRUE, axis.lty = 0, offset = 0, add = FALSE, summary = FALSE, rev = FALSE, level.lines = TRUE, ...)
height |
a vector of values describing the height of the bars that make up the plot. Matrices are not supported. |
width |
optional vector of bar widths. Re-cycled to length the number of bars drawn. Specifying a single value will have no visible effect unless 'xlim' is specified. |
space |
the amount of space (as a fraction of the average bar width) left before each bar. May be given as a single number or one number per bar. If not given explicitly, it defaults to 0.2. |
names.arg |
a vector of names to be plotted below each bar If this argument is omitted, then the names are taken from the 'names' attribute of 'height.' |
horiz |
a logical value. If 'FALSE', the bars are drawn vertically with the first bar to the left. If 'TRUE', the bars are drawn horizontally with the first at the bottom. |
density |
a vector giving the density of shading lines, in lines per inch, for the bars or bar components. The default value of 'NULL' means that no shading lines are drawn. Non-positive values of 'density' also inhibit the drawing of shading lines. |
angle |
the slope of shading lines, given as an angle in degrees (counter-clockwise), for the bars or bar components. |
col |
a vector of colors for the bars or bar components. By default, grey is used. |
border |
the color to be used for the border of the bars. Use 'border = NA' to omit borders. If there are shading lines, 'border = TRUE' means use the same colour for the border as forr the shading lines. |
main |
overall title for the plot. |
sub |
subtitle for the plot. |
xlab |
a label for the x-axis. |
ylab |
a label for the y-axis. |
xlim |
limits for the x-axis. |
ylim |
limits for the y-axis. |
xpd |
logical. Should bars be allowed to outside region? |
axes |
logical. If 'TRUE', a vertical (or horizontal, if 'horiz' is true) axis is drawn. |
axisnames |
logical. If 'TRUE', and if there are 'names.arg' (see above), the other axis is drawn (with 'lty=0') and labeled. |
cex.axis |
expansion factor for numeric axis labels. |
cex.names |
expansion factor for axis names (bar labels). |
plot |
logical. If 'FALSE', nothing is plotted. |
axis.lty |
the graphics parameter 'lty' applied to the axis and tick marks of the categorical (default horizontal) axis. Note that by default the axis is suppressed. |
offset |
initial offset relative to the x axis. The value serves as the logical starting point for the first column and any summary column. Defaults to 0. |
add |
logical specifying if bars should be added to an already existing plot; defaults to 'FALSE'. |
summary |
create a summary column. A summary column provides a final sum column showing the relative change from the offset. If a summary is requested and names.arg is set, the names.arg vector must include one extra entry with the summary column's name. Defaults to FALSE. |
rev |
reverse the order of columns? Defaults to FALSE. |
level.lines |
if FALSE, the lines connecting adjacent boxes are ommitted from the display. |
... |
arguments to be passed to other methods. For the default method these can include further arguments (such as 'axes', 'asp' and 'main') and graphical parameters (see 'par') which are passed to 'plot.window()', 'title()' and 'axis'. |
This function closely mimics the barplot interface, but provides a type of chart called a waterfall plot, showing how multiple subvalues contribute to a total sum.
This is a generic function, it currently only has a default method. A formula interface may be added eventually.
A numeric vector say 'mp', giving the coordinates of all the bar midpoints drawn, useful for adding to the graph.
Andrew Jaquith, Security Metrics: Replacing Fear, Uncertainty, and Doubt (Boston: Addison-Wesley Professional, 2007), 170-172.
Ethan M. Rasiel, The McKinsey Way: Using the Techniques of the World's Top Strategic Consultants to Help You and Your Business (New York: McGraw-Hill, 1999), 113-118.
data(rasiel) waterfallplot(rasiel$value, names.arg=rasiel$label)
data(rasiel) waterfallplot(rasiel$value, names.arg=rasiel$label)