# Additively applying EdgeStyle to a graph without resetting

w = {3, 4, 10, 2, 1};
g = Graph[{1 -> 2, 1 -> 3, 1 -> 4, 2 -> 3, 2 -> 4}, EdgeWeight -> w];
p = {1 -> 2, 1 -> 4};


Then I set their EdgeStyle to reflect the Edgeweights:

Table[PropertyValue[{g, e}, EdgeWeight], {e, EdgeList[g]}];
{min, max} = {Min[#], Max[#]} &@%
Do[PropertyValue[{g, e}, EdgeStyle] = AbsoluteThickness[Rescale[PropertyValue[{g, e}, EdgeWeight], {min, max}, {1, 7}]], {e, EdgeList[g]}]


However, I also want to color certain edges a color... so I attempt to use:

Do[PropertyValue[{g, e}, EdgeStyle] = {Green}, {e,p}]


The result is that the edges get colored green, except they are green without displaying the thickness I assigned to them earlier. I know why it's happening... I'm resetting EdgeStyle for those edges.

My attempt to circumvent this: I figured that we use Epilog here?-right? It gives me the same result when I use:

HighlightGraph[g, p, Epilog -> Green]


This gives me the same output as Do[PropertyValue[{g, e}, EdgeStyle] = {Green}, {e,p}]

How can I apply a color to certain edges once I've assigned their thicknesses?

• Do[PropertyValue[{g, e}, EdgeStyle] = Directive[Green, PropertyValue[{g, e}, EdgeStyle]], {e, p}]? May 20, 2017 at 19:02
• or HighlightGraph[g, Style[#, PropertyValue[{g, #}, EdgeStyle], Green] & /@ p]?
– kglr
May 20, 2017 at 19:34

## 1 Answer

As stated in the comment, what we can do is simply alter Do[PropertyValue[{g, e}, EdgeStyle] slightly to include the additional styling for subgraph p:

Table[PropertyValue[{g, e}, EdgeWeight], {e, EdgeList[g]}]; {min, max} = {Min[#], Max[#]} &@%
Do[PropertyValue[{g, e}, EdgeStyle] = AbsoluteThickness[Rescale[PropertyValue[{g, e}, EdgeWeight], {min, max}, {1, 7}]], {e, EdgeList[g]}]
Do[PropertyValue[{g, e}, EdgeStyle] = Directive[Green, PropertyValue[{g, e}, EdgeStyle]], {e, p}]


Alternatively, this can be applied with HighlightGraph as explain in the comments as well: HighlightGraph[g, Style[#, PropertyValue[{g, #}, EdgeStyle], Green] & /@ p]