5
$\begingroup$

I have a graph on which I want to highlight overlapping subset of vertices with a colored ring of larger radius and different color. So that I can see the vertices with multiple highlights. But with HighlightGraph I don't see any such option. This is what I was trying. But these are not rings, and I cannot check the overlaps with it.

With[{G = CompleteGraph[8], 
  H = {{1, 2, 3, 4}, {2, 3, 5, 6}, {2, 5, 7, 8}}, 
  C = {Red, Orange, Cyan}},
  HighlightGraph[G, Table[Style[H[[i]], Circle[], C[[i]]], {i, 1, Length@H}]]
 ]

enter image description here

$\endgroup$
6
$\begingroup$
 Module[{
  G = CompleteGraph[8],  H = {{1, 2, 3, 4}, {2, 3, 5, 6}, {2, 5, 7, 8}}, 
  C = {Red, Orange, Cyan}, S = {.05, .03, .01}, pos
 }, 
 pos = AssociationThread[VertexList[G] -> GraphEmbedding@G];
 Show[G, Graphics[ 
  MapThread[{#2, Thick, Thread@Circle[#3 /. pos, Scaled@#1]} &, {S,  C, H}]
 ]]]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks That worked, Nice But this is not graph anymore, it becomes a graph object. $\endgroup$ – Neel Basu Jan 10 '18 at 11:37
  • $\begingroup$ @NeelBasu you can still work with original graph, this is for a visualization, or do you need a graph at the end? $\endgroup$ – Kuba Jan 10 '18 at 11:38
  • $\begingroup$ Nope so far this is okay with Graphics. But these are filled circle, Can you make them transparent ? $\endgroup$ – Neel Basu Jan 10 '18 at 11:44
  • $\begingroup$ @NeelBasu Replace Point with whatever you want. $\endgroup$ – Kuba Jan 10 '18 at 11:44
6
$\begingroup$

Using a custom VertexShapeFunction:

ClearAll[vShape]
vShape[h_, c_, s_] := Module[{hc = Thread /@ 
  Thread[h -> (Function[k, {#, Circle[k, Scaled@#2]}] & @@@ Thread[{c, s}])], hr}, 
  hr = #[[1, 1]] -> #[[All, 2]] & /@ GatherBy[Join @@ hc, First]; 
  If[MemberQ[Union@Flatten@h, #2], Through[(#2 /. hr)@#], Disk[#, Scaled[.01]]] &]

Examples:

H = {{1, 2, 3, 4}, {2, 3, 5, 6}, {2, 5, 7, 8}};
Col = {Red, Orange, Cyan};
S = {.05, .03, .01};

CompleteGraph[8, VertexShapeFunction -> vShape[H, Col, S]]

enter image description here

CompleteGraph[8,  VertexShapeFunction -> 
  vShape[{{1, 2, 3}, {2, 3, 4}, {1, 3, 5}, {1, 2, 4, 6}},
 {Orange, Green, Blue, Directive[Thick, Red]}, Range[.01, .04, .01]]]

enter image description here

$\endgroup$
  • $\begingroup$ With Complete Graph it works fine. But when I was trying this on my actual graph, which is big an rectangular. all these circles came as eclipses. So I removed Scaled. $\endgroup$ – Neel Basu Jan 10 '18 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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