I want to find a nice way to display driving distances, but got stuck with the following problem:
1. Example data
vlist = {"Boston" -> 0, "Chicago" -> 80, "Denver" -> 160,
"Eugene" -> 40, "Fresno" -> 40, "Gary" -> 50, "Houston" -> 180,
"Irvine" -> 120, "Mobile" -> 50};
wlist = {"Boston" -> 0, "Canton" -> 100, "Dayton" -> 220,
"Erie" -> 70, "Francfort" -> 40, "Gary" -> 90, "Haggerton" -> 140,
"Mobile" -> 200};
vcum = Accumulate @ Values @ vlist;
vvals = Map[Append[1] @* List] @ vcum;
vplot = Transpose[{vvals, Keys @ vlist}] /. {{a_, b_}, c_} :> Callout[{a, 1}, c];
wvals = Map[Append[2] @* List] @ Accumulate @ Values @ wlist;
wplot = Transpose[{wvals, Keys @ wlist}] /. {{a_, b_}, c_} :> Callout[{a, 2}, c];
2. First possibility
ListPlot[{vplot, wplot},
AspectRatio -> 1/4,
BaseStyle -> Thickness[0.0015],
Frame -> True,
FrameTicks -> {{{1, 2}, None}, {vcum, None}},
GridLines -> {vcum, None},
GridLines -> {Automatic, None},
ImageSize -> 700,
PlotMarkers -> "OpenMarkers",
PlotRange -> {All, {0.5, All}},
Epilog ->
{{ColorData[97, "ColorList"][[1]], Line[{{0, 1}, {Max @ vvals, 1}}]},
{ColorData[97, "ColorList"][[2]], Line[{{0, 2}, {Max @ wvals, 2}}]}}
]
The advantages of this display form are the scaled distances between towns and the scaling between the two alternate routes. One big disadvantage is that we don't directly see the distance from one town to the next town. With other words: I don't know how to place a label of 160
between Chicago
and Denver
.
2. Second possibilty
The latter problem is nicely solved in this answer of kglr
:
List processing to find distances between towns
vpath = Thread[Keys @ vlist -> vcum];
PathGraph[vpath[[All, 1]],
EdgeWeight -> Differences[vpath[[All, 2]]],
EdgeLabels -> Placed["EdgeWeight", {1/2, {1/2, 3/2}}],
VertexWeight -> vlist,
VertexLabels -> {v_ :> Placed[{v, v /. vpath}, {Above, Below}, Rotate[#, 90 Degree] &]},
ImageSize -> Large,
BaseStyle -> 10]
The disadvantage here is the missing scaling between the towns. Not being familiar at all with the countless Graph
display options, I don't know how to overcome this limitation.
3. Question
Can we combine the advantages of ListPlot
(scaling) and PathGraph
(labeling)?
4. Note
The addition of an alternate route is purely optional