Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
THere are several examples in the documentation for VertexRenderingFunction. The help file will show you how to apply it. –  bill s Jun 5 '13 at 19:41
1  
Something like HighlightGraph[Graph[{1 -> 2, 1 -> 3, 3 -> 4, 4 -> 1}], {1 -> 2, 1 -> 3}]? –  J. M. Jun 5 '13 at 19:43
    
@0x4A4D Yes almost, like that.However, please see edit. –  smilingbuddha Jun 5 '13 at 19:51
1  
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]}] &)] –  belisarius Jun 5 '13 at 21:59
1  
@Anon I posted an answer, let's see if the community thinks it has some value –  belisarius Jan 13 at 0:23
show 3 more comments

1 Answer

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]}] &)]

Mathematica graphics

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.