Labeling Legs in a Loop on a graph

I am trying to make a graph with some loops such as this one,

GraphPlot[{{2 -> -2, "a"}, {-2 -> 2, "b"}, {2 -> 6, "b"}, {6 -> 8, "b"}, {8 -> 10, "b"}, {10 -> 8, "c"}}]


Where the output is

In my GraphPlot function, I have 2 -> -2 labeled as "a" and -2 -> 2 as "b". Instead, Mathematica chooses the first instance and gives the other leg in the loop the same label. So for example, if I were to switch the ordering {2 -> -2,"a"} and {-2 -> 2,"b"} that loop would be labeled as "b,b" instead of "a,a". Any suggestions on how to make the loop labeled as "a,b" would be much appreciated!

• if you have a version before v12, GraphPlot works better (you get the desired/expected output).
– kglr
Aug 27, 2019 at 23:48
• Ya, unfortunately, I updated to v12 and I am thinking about reverting back now. Aug 28, 2019 at 0:00
• do you have multi-edges in your edge list?
– kglr
Aug 28, 2019 at 0:14
• I ended up taking your original suggestion and reverted back to 11.3 and this solved all of the issues I was having with GraphPlot. Thanks for the info. Aug 28, 2019 at 2:06
– kglr
Aug 28, 2019 at 8:38

You could do

GraphPlot[{{2 -> -2, "a"}, {-2 -> 2, "b"}, {2 -> 6, "b"}, {6 -> 8,
"b"}, {8 -> 10, "b"}, {10 -> 8, "c"}}, DirectedEdges -> True,
EdgeShapeFunction -> "Line"]


Update: Re "reverted back to 11.3 and this solved all of the issues I was having with GraphPlot."

Losing quiet a few convenient features (including -- unlike Graph -- handling labeling of multi-edges correctly) with the v12 update to GraphPlot probably dismayed many users and WRI must have anticipated that. Following the hunch that the old GraphPlot can not possibly be completely inaccessible in v12, a simple search revealed GraphComputationGraphPlotLegacy.

Hence no need to down-grade to v11 to be able to use the legacy GraphPlot and no need to look for work-arounds to replicate the legacy functionality ... just use GraphComputationGraphPlotLegacy:

GraphComputationGraphPlotLegacy[{{2 -> -2, "a"}, {-2 -> 2, "b"}, {2 -> 6, "b"},
{6 -> 8, "b"}, {8 -> 10, "b"}, {10 -> 8, "c"}},
MultiedgeStyle -> 1/2, BaseStyle -> 14, ImageSize -> 600]


With multi-edges

GraphComputationGraphPlotLegacy[{{2 -> -2, "a"}, {2 -> - 2,  "b"},
{2 -> - 2, "c"}, {2 -> 6, "b"}, {6 -> 8, "b"}, {8 -> 10, "w"},
{8 -> 10, "x"}, {8 -> 10, "y"}, {8 -> 10, "z"}},
MultiedgeStyle -> 1/2, BaseStyle -> 14, ImageSize -> 600]


If you don't have multi-edges, you can replace -> with \[DirectedEdge] in your edge list (or use the option DirectedEdges->True as in halmir's answer) and add the option EdgeStyle -> Arrowheads[0]:
el = {{2 -> -2, "a"}, {-2 -> 2, "b"}, {2 -> 6, "b"}, {6 -> 8, "b"},