For displaying the total effect of a series of values, a waterfall chart can be useful. For example this chart, taken from The Economist, illustrates estimated efficiency potentials in the UK public sector:
I know how to produce a chart like this with TikZ,
but this doesn't seem to be the most elegant way. pgfplots
does offer bar charts with the ybar stacked
option, but I am not able to really reproduce what I want. By taking the the code from this question, I got this far. Is it possible to further improve this: eg. divide the bars and correctly number the parts? And maybe there is a solution that is easier to modify? For example, rescaling the y-Axes messes up the last line from increased tax collection to total.
\documentclass{article}
\usepackage{pgfplots}
\pgfdeclareplotmark{waterfall bridge}{\pgfpathmoveto{\pgfpoint{-8pt}{0pt}}\pgfpathlineto{\pgfpoint{48pt}{0pt}}\pgfusepathqstroke}
\pgfdeclareplotmark{waterfall bridge 2}{\pgfpathmoveto{\pgfpoint{32pt}{0pt}}\pgfpathlineto{\pgfpoint{88pt}{0pt}}\pgfusepathqstroke}
\pgfdeclareplotmark{waterfall bridge 3}{\pgfpathmoveto{\pgfpoint{72pt}{116pt}}\pgfpathlineto{\pgfpoint{128pt}{116pt}}\pgfusepathqstroke}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
bar width=16pt,
axis lines*=middle,
axis on top=false,
xtick={1.00},
xticklabels={Enhanced \\Operational \\Efficency},
ymin=0, xmin=.95, xmax=1.1,
enlarge y limits=0.2,
after end axis/.code={
\node at ({rel axis cs:0,0}|-{axis cs:0,0}) [anchor=east] {0};
},
nodes near coords, nodes near coords align={center},
]
\addplot[
fill=cyan,
draw=none,
bar shift=0pt,
mark options={
gray,
thick
},
mark=waterfall bridge
] coordinates { (1, 22) };
\addplot[
fill=orange,
draw=none,
bar shift=40pt,
mark options={
gray,
thick
},
mark=waterfall bridge 2
] coordinates { (1,+3) };
\addplot[
fill=orange,
draw=none,
bar shift=80pt,
] coordinates { (1,+8) };
\addplot[
fill=orange,
draw=none,
bar shift=120pt,
mark options={
gray,
thick
},
mark=waterfall bridge 3
] coordinates { (1,-33) };
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
You can use
ybar stacked
with an invisible third series for getting the vertical offset, and aconst plot
for the connecting lines. To place the labels, you can use the approach from Center nodes near coords in a stacked ybar plot.Here's an example: