# Subset of edges with a different color

I want to color a subset of the edges of my graph with a different color. My graph currently has a large number of edges, so the following is just a toy example

s = {1->2,1->3}
g = {1->2, 1->3,3->4,4->1}
GraphPlot[g,VertexLabeling->True]


Here s is a subset of g I would like to tell GraphPlot to plot the edges in s with a different color, and make the edges of s directed.

How to do this?

EDIT:

The closest I have coming after looking at some answer to another question on this site is

s = {{1,2},{1,3}}
g = {1->2, 1->3,3->4,4->1}
GraphPlot[g,VertexLabeling->True,EdgeRenderingFunction -> (If[
Intersection[s, {#2}] != {}, {Red ,Arrow[#1, .1]},
{Blue,Arrow[#1, .1]}] &)]


However, since I want the complement of the set s in g to be represented as blue segment (and not an arrow) I am not sure what I should write in place of Arrow inside {Blue,Arrow[#1, .1]} above.

• THere are several examples in the documentation for VertexRenderingFunction. The help file will show you how to apply it. Commented Jun 5, 2013 at 19:41
• Something like HighlightGraph[Graph[{1 -> 2, 1 -> 3, 3 -> 4, 4 -> 1}], {1 -> 2, 1 -> 3}]? Commented Jun 5, 2013 at 19:43
• @J. M. Yes almost, like that.However, please see edit. Commented Jun 5, 2013 at 19:51
• s = {{1, 2}, {1, 3}} g = {1 -> 2, 1 -> 3, 3 -> 4, 4 -> 1} GraphPlot[g, VertexLabeling -> True, EdgeRenderingFunction -> (If[ Intersection[s, {#2}] != {}, {Red, Line[#1]}, {Blue, Arrow[#1, .1]}] &)] Commented Jun 5, 2013 at 21:59
• @C. E. I posted an answer, let's see if the community thinks it has some value Commented Jan 13, 2014 at 0:23

s = {{1, 2}, {1, 3}};
g = {1 -> 2, 1 -> 3, 3 -> 4, 4 -> 1} ;
GraphPlot[g, VertexLabeling -> True,
EdgeRenderingFunction -> (If[s ⋂ {#2} != {}, {Red, Arrow[#1, .1]}, {Blue, Line[#1]}] &)]


HighlightGraph has been mentioned in the comments, and you responded to that comment, but it is still not clear to me when you cannot use this function.

HighlightGraph[
Graph[g, GraphStyle -> "VintageDiagram", EdgeStyle -> Blue],
Style[s, Red]
]


• GraphStyle -> "VintageDiagram" uses the style of GraphPlot with Graph
• EdgeStyle -> Blue makes the default edge colour blue
• HighlightGraph[..., Style[s, Red]] highlights the edges listed in s in Red.

Using Graph with options EdgeStyle:

Graph[g, GraphStyle -> "VintageDiagram",
EdgeStyle -> {_ -> Directive[Arrowheads[0], Blue],
## & @@ Thread[s -> Directive[Opacity[1], Thick, Red]]}]


Same result with a combination of options EdgeStyle and EdgeShapeFunction:

EdgeStyle -> Prepend[Thread[s -> Directive[Opacity[1], Thick, Red]], _ -> Blue]


and

EdgeShapeFunction -> Prepend[Thread[s -> "Arrow"], _ -> "Line"]