# Plot a tripartite Graph with its groups separated

I would like to create a Graph like the following:

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.

• 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 Commented Apr 19, 2015 at 12:35
• You should clarify your question and maybe provide an example of the desired output :)
– Öskå
Commented Apr 19, 2015 at 12:37

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


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

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


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


or

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


to compare with alternative vertex layouts:

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


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


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


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