CommunityGraphPlot without force layout
If you want to draw blob like CommunityGraphPlot:
iBlobs[style_, pts_, size_] :=
Block[{epts},
epts = Flatten[Tuples[CoordinateBounds[#, size]] & /@ pts, 1];
{style,
FilledCurve@
BSplineCurve[MeshPrimitives[ConvexHullMesh[epts], 1][[All, 1, 1]],
SplineClosed -> True]}
]
{cliques, style} = {{{1, 2, 3}, {4, 5}, {4, 8}}, {Red, Green, Blue}};
vcoord = GraphEmbedding[g];
bsize = .08 Differences[MinMax[vcoord]][[1]];
bstyle = Directive[Opacity[.3], EdgeForm[#], #] & /@ style;
cpoints = vcoord[[VertexIndex[g, #] & /@ #]] & /@ cliques;
HighlightGraph[g, cliques,
Epilog ->
Activate[Thread[Inactive[iBlobs][bstyle, cpoints, bsize]]],
ImagePadding -> 20]
Update: Using GraphComputation`GraphCommunitiesPlotDump`generateBlobs
, ... well, to generate blobs:
ClearAll[blobF, fC]
fC[coords_, size_: .04] := Module[{}, CommunityGraphPlot[Graph[{}], {}];
FilledCurve @ BSplineCurve[GraphComputation`GraphCommunitiesPlotDump`generateBlobs[# &,
{coords}, size][[2, 1]], SplineClosed -> True]]
blobF[g_, cols_, coms_, size_: .04] := Thread[{cols, EdgeForm[{Gray, Thin}], Opacity[.25],
fC[PropertyValue[{g, #}, VertexCoordinates] & /@ #, size] & /@ coms}];
{cliques, colors} = {{{1, 2, 3}, {4, 5}, {6, 7, 8}}, {Red, Green , Blue}};
cg = CompleteGraph[8];
SetProperty[cg, {Epilog -> blobF[cg, colors, cliques],
VertexLabels -> "Name", ImagePadding -> 15}]
SeedRandom[1]
Row[{#, SetProperty[#, {Epilog -> blobF[#, colors, cliques], ImagePadding -> 15}]} &@
RandomGraph[{20, 15}, ImageSize -> 300, VertexLabels -> "Name"]]
Original answer:
{cliques, colors} = {{{1, 2, 3}, {4, 5}, {6, 7, 8}}, {Red, Green , Blue}};
lines = Thread[{colors, CapForm["Round"], JoinForm["Round"],
Opacity[.5], AbsoluteThickness[20],
Line[PropertyValue[{cg, #}, VertexCoordinates] & /@ #] & /@ cliques}];
SetProperty[CompleteGraph[8], {Epilog -> lines, VertexLabels -> "Name",
ImagePadding -> 15}]
Or highlight Subgraph
s:
cg = CompleteGraph[8];
Fold[HighlightGraph[##] &, cg, (Style[Subgraph[cg, #[[1]]], #[[2]],
CapForm["Round"], JoinForm["Round"], AbsoluteThickness[20]] & /@
Transpose[{cliques, colors}])]