Graph Union with Color Properties Kept
I do not use Graph much at all. But playing with it, it looks like styling is lost when making union.
A workaround meanwhile is to do this
edges1 = {NS <-> N1, NS <-> N2, N2 <-> N3, N3 <-> N1};
edges2 = {NS <-> S1, S1 <-> S3, S2 <-> N2, N2 <-> NS};
vs1 = {NS | N1 | N2 -> Red, N3 -> Blue};
vs2 = {S1 | S2 | S3 -> Yellow};
g1 = Graph[edges1, VertexLabels -> "Name", VertexLabels -> Automatic,
VertexSize -> 0.2, VertexStyle -> vs1]
g2 = Graph[edges2, VertexLabels -> "Name", VertexLabels -> Automatic,
VertexSize -> 0.2, VertexStyle -> vs2]
Now
GraphUnion[g1, g2, VertexLabels -> "Name", VertexSize -> 0.2, VertexStyle -> Join[vs1, vs2]]
i.e need to apply styles manually again. This seems like a feature limitation. May be submit feature request to WRI on this by emailing [email protected]
ClearAll[grUnion]
grUnion = GraphUnion[##,
Normal@GroupBy[Join @@ (Options /@ {##}), First -> Last, Apply[Union]]] &;
grUnion[g1, g2]
You can add new options and/or replace existing one using Graph[grUnion[g1,g2], options]
:
Graph[grUnion[g1, g2],
VertexLabels -> Placed["Name", Center],
VertexLabelStyle -> {Alternatives @@ VertexList[g1] -> White},
ImageSize -> Large]