The slopegraph is described in Edward Tufte's book The Visual Display of Quantitative Information (1983).
This example illustrates this kind of visual display using the barley
dataset. The spec should automatically work for multi-year slopegraphs. The key is
to manually adjust the first_year
and last_year
comparison figures (i.e. 1931
and 1932
) in the top-level transform
, which serve to position the first and last site
labels.
The main design issue is to avoid the collision of the labels, in this case for the
sites Morris and Grand Rapids in 1931 as well as the sites Morris and Waseca in 1932.
Obviously, collision strongly depends on the data and there is no general solution in
vega-lite
. I have mostly tried to deal with the issue by increasing the height
and
width
parameters - you may find this solution to be extreme. Other solutions are possible:
- use the
size
encoding channel to reduce the font size for theyield
andsite
fields; - by editing the compiled Vega spec, apply specific production rules for the colliding labels in question, e.g. by reducing only their font size. This is probably the solution you will use if you want a publication-ready visual display;
This block has been forked from Domoritz's Vega-Lite Block example.