I am trying to create a BarChart
visualization for multi-step data filtering. Think of a traditional sales funnel: many leads, fewer prospects, few customers, very few return customers. The only kicker is, I want to show the percentage of data being lost by using Percentile layout for the BarChart
, and I want to show that the slice of previous bar is the entirety of the content of the next bar using lines similar to Joined option, and if possible, fill the joining lines with color similar to the one used for selection.
Lastly,for my data content, there are 2 types of filters: binary (e.g. lead becomes prospect or not) and slice-of-pie (e.g. customers who spent between X
and Y
, where the slice would appear in the middle of the column, with rest of sales with lower amount appearing below, and higher amount appearing above). I can draw this using Graphics
and basic primitives, but was really hoping that there's a clever way to adapt BarChart
, so that I could use the built-in labeling or legending features, as well as the vertical axis. Or even go from Percentile
to Stacked
, as needed.
Here's a simple drawing of what I envision this could look like:
And if anyone can suggest an alternate visualization which will serve the purpose, I'd really appreciate it. I thought of using TreeGraph
with VertexSize
option, but it's less than trivial to visualize not only what made it into the filter, but also how much are you losing and where the loss occurs.
UPDATE:
Thanks to @Verbeia's clever solution, and a little bit of additional engineering, this is what I came up with. Clearly there's endless room for improvement, but the automation works great.
data = {{4, 3, 4.5, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 3, 5, 6, 0,
0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0}, {0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 1, 1}};
lines = Flatten[Table[{
{{1.501 n,
100 data[[n, 3 n - 2]]/Total@data[[n]]}, {1.5 n + .499,
0}}, {{1.501 n,
100 (data[[n, 3 n - 2]] + data[[n, 3 n - 1]])/
Total@data[[n]]}, {1.5 n + .499, 100}}}
, {n, 1, 3}], 1];
Show[
BarChart[data, ChartLayout -> "Percentile",
BarSpacing -> {None, .5}, ChartStyle -> "Pastel"],
ListLinePlot[lines,
Filling ->
Table[(2 n - 1) -> {{2 n},
Directive[[email protected],
ColorData["Pastel"][(3 n - 2)/(3 4)]]}, {n, 1, 3}],
PlotStyle -> Directive[Dashed, Gray]]
, ImageSize -> 850]
And the result: