# Coloring edges in GraphPlot

I'm a little stuck with graph drawing part of my research — I can't use the Graph function for plotting my graphs, because my graph is a multi-graph. Graph is convenient because it colors edges quite easily.

Since I have a 3-regular (or even 4-regular) graph, where there are 3 (or 4) perfect matching, I want each of the matching to be colored differently.

What's the best way to color a group of edges (each perfect matching with it's own color) in the given adjacency list in GraphPlot? To simplify it, we can assume, that groups goes one by one (e.g. we have 6 edges: 3 groups of two edges, following each other

{1<->2, 3<->4, 1<->3, 2<->4, 1<->2, 3<->4}


In Graph, I've constructed a nice lambda function, that wraps all elements of a list in a Style function, that colors the edge. But in a GraphPlot I can't wrap edges in a Style function.

There's an EdgeRenderingFunction, wich draws all the edges. How do I put three different EdgeRenderingFunctions for the one edge-set? Or is that the wrong way to go?

Any ideas, how to do that?

The labeled answer is absolutely correct. Little generalization of what I needed and how to implement it:

  GraphPlot[{{1 -> 2, 1}, {3 -> 4, 1}, {1 -> 3, 2}, {2 -> 4, 2}, {1 -> 2, 3},
{3 -> 4, 3}}, MultiedgeStyle -> .2,
EdgeRenderingFunction -> (Switch[#3, 1, {Red, Line[#1]},
2, {Blue, Line[#1]}, 3, {Green, Line[#1]},
4, {Dashed, Line[#1]}] &), VertexLabeling -> True,
Method -> "CircularEmbedding"] • Have you tried using EdgeRenderingFunction? – Eli Lansey Apr 19 '12 at 18:03
• That's one of the first things I've looked into. But I haven't found a way to implement three different EdgeRenderingFunction for the same graph, separating edge groups. – Sergey Aganezov jr Apr 19 '12 at 19:04

l = {{1, 3}, {3, 4}};
GraphPlot[{1 -> 2, 3 -> 4, 1 -> 3, 2 -> 4, 1 -> 2, 3 -> 4},
EdgeRenderingFunction -> (If[
Intersection[l, {#2}] != {}, {Red, Arrow[#1, .1]},
{Blue,Arrow[#1, .1]}] &)] Edit

Using edge labels:

l = {1, 3};
GraphPlot[{{1 -> 2, 1}, {3 -> 4, 2}, {1 -> 3, 3}, {2 -> 4, 4}, {1 -> 2, 5}, {3 -> 4, 6}},
EdgeRenderingFunction -> (If[
Intersection[l, {#3}] != {}, {Red, Arrow[#1, .1]}, {Blue, Arrow[#1, .1]}] &)] • Thanks for such a quick response! Your example helps me to understand that EdgeRenderingFunction deeper, than earlier. But your way has two disadvantages for me: 1) a have to create some special set to work with, which is quite difficult, since a want to visualize a lot of data 2) in your code there're two matchings that are highlighted with the same color. You way works with the edge properties, but if there're two same edge sets, that I want to highlight differently, it won't work. I was thinking about coloring them according to their number in the given edge list. – Sergey Aganezov jr Apr 19 '12 at 18:26
• @SergeyAganezovjr See edit – Dr. belisarius Apr 19 '12 at 18:40
• Now it's exactly what I needed! Thanks a lot! – Sergey Aganezov jr Apr 19 '12 at 18:51
• Never crossed my mind, I can use the label option of an edge as a color-switcher one! – Sergey Aganezov jr Apr 19 '12 at 19:01
• @SergeyAganezovjr You can consider it a "tag" for storing useful info about the graph. – Dr. belisarius Apr 19 '12 at 19:07

I interpreted the problem as requiring two different colors if the edges were duplicated:

normal[{x_, y_}] := 0.03*{-y, x}/Norm[{x, y}];
GraphPlot[{1 -> 2, 3 -> 4, 1 -> 3, 2 -> 4, 1 -> 2, 3 -> 4},
VertexLabeling -> True,
EdgeRenderingFunction -> (If[Length[#1] > 2,
norm = normal[First[#1] - Last[#1]]; {Red,
Arrow[{First[#1] + norm, Last[#1] + norm}, .08], Blue,
Arrow[{First[#1] - norm, Last[#1] - norm}, .08]},
Arrow[#1, .08]] &)] • thanks for your answer, that's another way to look at my problem. Sorry for that formulation; my goal was to color different perfect matchings with different colors. – Sergey Aganezov jr Apr 19 '12 at 19:02
• Perhaps I don't understand what is meant by a "perfect matching". Would you kindly explain? – DavidC Apr 19 '12 at 19:08
• Sure. You can find some info about that here and here. In simple terms: it's an edge set, that covers all the vertices, and there're no two edges, that would contain the same vertex. – Sergey Aganezov jr Apr 19 '12 at 19:24
• Thanks for the explanation and links. – DavidC Apr 19 '12 at 23:34