3
$\begingroup$

I would like to create a Graph like the following:

enter image description here

but without edges between vertices in the same group.

So I have a graph and I want to plot it such that its vertices are separated into 3 groups away from each other, I prefer that each group is not in line form, but better to be in random form.

$\endgroup$
2
  • $\begingroup$ no no, I mean that since it is a tripartite, there will be no edges between vertices inside each group. Anyway I just want to plot a graph and separate it into 3 groups in different locations $\endgroup$ Commented Apr 19, 2015 at 12:35
  • 1
    $\begingroup$ You should clarify your question and maybe provide an example of the desired output :) $\endgroup$
    – Öskå
    Commented Apr 19, 2015 at 12:37

1 Answer 1

5
$\begingroup$

Update 2: Hiding the edges within the same community for general (not-necessarily tri-partite) graphs:

ClearAll[insideEdges]
insideEdges[g_, c_]:=Select[EdgeList[g], Or @@ (Function[x, SubsetQ[x, {##}] ]/@c)& @@ #&]

Examples:

zkc = ExampleData[{"NetworkGraph", "ZacharyKarateClub"}];

CommunityGraphPlot[zkc,  CommunityRegionStyle -> {LightRed, LightGreen, LightBlue},
 EdgeStyle -> {Alternatives @@ insideEdges[zkc, FindGraphCommunities[zkc]] :> Opacity[0]}]

enter image description here

dsn= ExampleData[{"NetworkGraph", "DolphinSocialNetwork"}];

CommunityGraphPlot[dsn,  CommunityRegionStyle -> 97,
 EdgeStyle -> {Alternatives @@ insideEdges[dsn, FindGraphCommunities[dsn]] :> Opacity[0]}]

enter image description here

Update 1:

athreepartitegraph = CompleteGraph[{10, 7, 3}, 
  GraphLayout -> {"MultipartiteEmbedding",  "VertexPartition" -> {10, 7, 3}},
  ImageSize -> 400, VertexLabels -> "Name", ImagePadding -> 20];

cgp = CommunityGraphPlot[athreepartitegraph, 
       {Range[10], Range[11, 17], Range[18, 20]}, Method -> "Hierarchical"];
Row[{athreepartitegraph, cgp}] 

enter image description here

or

CommunityGraphPlot[athreepartitegraph, 
  {Range[10], Range[11, 17], Range[18, 20]}, Method -> "SpringElectrical"]

enter image description here

to compare with alternative vertex layouts:

Row[SetProperty[athreepartitegraph, 
    GraphLayout -> #] & /@ {{"CircularEmbedding"}, 
      {"CircularMultipartiteEmbedding", "VertexPartition" -> {10, 7, 3}}}]

enter image description here


Original post:

Maybe something like:

g2 = ExampleData[{"NetworkGraph", "ZacharyKarateClub"}];
g2 = SetProperty[g2, {VertexLabels -> "Name", ImagePadding -> 20, ImageSize -> 400}];

fgp = FindGraphPartition[GraphComplement[g2], 3];
mpg = Graph[Flatten@fgp, EdgeList[g2], 
   GraphLayout -> {"MultipartiteEmbedding", "VertexPartition" -> (Length /@ fgp)},
   VertexLabels -> "Name", 
   ImagePadding -> 20, ImageSize -> 400];

Row[{g2, mpg}]

enter image description here

CommunityGraphPlot[g2, fgp, Method -> "Hierarchical"]

enter image description here

$\endgroup$
5
  • $\begingroup$ I tried that, but I don't want the vertices to be in lines because I will use large graphs $\endgroup$ Commented Apr 19, 2015 at 12:38
  • $\begingroup$ @Ahned, if the layout is the issue, does something like CommunityGraphPlot[g2, fgp, Method -> "Hierarchical"] give something closer to what you need? $\endgroup$
    – kglr
    Commented Apr 19, 2015 at 12:45
  • $\begingroup$ yes the layout is the problem but I need to make my own groups $\endgroup$ Commented Apr 19, 2015 at 12:48
  • $\begingroup$ @kguler the original and the update are very instructive beyond question...thank you again +1 :) $\endgroup$
    – ubpdqn
    Commented Apr 20, 2015 at 8:09
  • $\begingroup$ @ubpdqn, i appreciate the kind words. $\endgroup$
    – kglr
    Commented Apr 21, 2015 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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