A better alternative to the paired bar chart
Here is a version that builds up the "full Tufte" version of the plot presented above by building up the corresponding Graphics
primitives. Quite a few styling decisions must be made with respect to colors, spacings, overall aspect ratio of the plot, etc. I went with choices that were aesthetically pleasing to me, but of course it should be relatively easy to tweak those within the function.
The vertical sorting of the data points is also somewhat arbitrary. At this point the data is presented in such a way that the points with lowest first Gini coefficient show up at the bottom, and in the case of a tie, they are ordered by the alphabetical order of their labels (because of the way SortBy
works). If that is undesirable, one should adjust the sorting function in SortBy
: for instance, a stable sort such as SortBy[{#[[2]]&}]
would leave tied elements in the original order in which they were present in the dataset, etc.
The horizontal PlotRange
is adjusted somewhat automatically to include the labels as well by including an asymmetric PlotRangePadding
in the $x$ direction. This is somewhat brittle because the length of the label strings is never taken into explicit consideration. I have the impression that there should be a combination of PlotRange / Padding / Clipping that could take care of that automatically, but at this moment it slips my mind.
fullTufte[dataset_] :=
Graphics[
Flatten@MapIndexed[
Function[{item, index},
{
(*heading*)
Black, Text[item[[1]], {item[[2]] - 0.35, First@index}, {1, 0}],
(*line*)
Gray, Line[{{item[[2]], First@index}, {item[[3]], First@index}}],
(*numbers*)
Darker@Blue,
Inset[item[[2]], {item[[2]], First@index}, {0, 0}, Background -> White],
Orange, Inset[item[[3]], {item[[3]], First@index}, {0, 0}, Background -> White]
}
],
SortBy[#[[2]] &][dataset]
],
PlotRange -> All, PlotRangeClipping -> False,
PlotRangePadding -> {{Scaled[0.3], Scaled[0.05]}, Automatic},
AspectRatio -> 1.6,
Axes -> {True, False}
]
Here is the result of its application to the giniCoefficients
dataset:
fullTufte[giniCoefficients]
In version 10+ there is NumberLinePlot
that can be used for this.
NumberLinePlot[Interval[Rest@#] & /@ Reverse[giniCoefficients, 1],
PlotStyle -> (Directive[#, Thin, PointSize[Large]] & /@ {Orange,
Blue}),
PlotRange -> {{2, Automatic}, Automatic},
PlotRangePadding -> Scaled[.05],
Epilog ->
MapIndexed[
Function[{item, index},
Inset[First@item, {item[[2]] - .05, First@index}, {1, 0}]],
Reverse[giniCoefficients, 1], 1]]
There are a couple of things that I don't know how to do that I'd like to be able to without a ReplaceAll
hack on the plot.
- Find the length of the text in the graphic so a proper lower
PlotRange
can be set. - Define a
PlotStyle
that gives either of the styles the OP requested.
Hopefully someone will add an answer with those features.