# Problem setting up edge rendering function

I have a graph, and I want my EdgeRenderingFunction to colour the edges based on the vertex they originate from. In this toy example, I'm trying to get the edge originating from vertex 1 to be red:

GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 5 -> 1, 5 -> 2, 5 -> 3, 5 -> 4,
1 -> 4, 3 -> 5, 3 -> 3},
EdgeRenderingFunction -> (If[First[#1] === 1, {Red, Line[#1]},
Line[#1]] &), VertexLabeling -> True]


What am I doing wrong? I was following the (slightly more complicated) model given in the Mathematica documentation:

GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 5 -> 1, 5 -> 2, 5 -> 3, 5 -> 4,
1 -> 4, 3 -> 5, 3 -> 3},
EdgeRenderingFunction -> (If[
Length[#1] > 2, {Red, Line[#1],
Text[If[First[#1] === Last[#1], "loop", "multiedge"],
LineScaledCoordinate[#1, .7], Background -> White]},
Line[#1]] &), VertexLabeling -> True]


-
Maybe GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 5 -> 1, 5 -> 2, 5 -> 3, 5 -> 4, 1 -> 4, 3 -> 5, 3 -> 3}, EdgeRenderingFunction -> (If[First[#2] === 1, {Red, Line[#1]}, Line[#1]] &), VertexLabeling -> True] ? –  b.gatessucks Oct 22 '12 at 12:19
hmm, why then in the documentation example does #1 work? I thought the first argument is the x->y connections? –  Ooku Oct 22 '12 at 12:22
I just read the first point under More Information here and it seems that you need the vertices (2nd argument). –  b.gatessucks Oct 22 '12 at 12:24
Ah, mis-read "beginning and end points" as "beginning and end vertices". Thanks. –  Ooku Oct 22 '12 at 12:35

Try this:

GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 5 -> 1, 5 -> 2, 5 -> 3, 5 -> 4, 1 -> 4, 3 -> 5, 3 -> 3},
EdgeRenderingFunction -> (If[MemberQ[#2, 1], {Red, Line[#1]}, Line[#1]] &),
VertexLabeling -> True]


The docs for EdgeRenderingFunction are a bit subtle, but there is the note that any such function must take the vertices as the second argument.

-
Thanks, although to be precise, direction matters, but otherwise, this is the answer I was looking for –  Ooku Oct 22 '12 at 12:36
In that case, replace MemberQ[#2, 1] with First[#2] == 1. –  Guess who it is. Oct 22 '12 at 12:39
@J.M. Out of curiosity, how come the image is flipped ? –  b.gatessucks Oct 22 '12 at 14:30
I don't quite know why, @b.gatessucks. That's how it came out on the machine I'm using (8.0.4 on Fedora 17). –  Guess who it is. Oct 22 '12 at 14:33
@J.M. Same setup at home, will try later. –  b.gatessucks Oct 22 '12 at 14:37