Visualizing subgraphs while specifying the locations of vertexes
This seems to work pretty well:
r = 0.2/3;
regions = RegionPlot[
Evaluate@Table[
Length@clique PDF[SmoothKernelDistribution[data[[clique]], r], {x, y}] > 1/(4 π r^2),
{clique, mycliques}],
{x, -2 r, 1 + 2 r}, {y, -2 r, 1 + 2 r}, Frame -> False];
Show[regions, Graph[mygraph, GraphStyle -> "BasicBlack"]]
Further reading: metaballs.
Update 2: Generating blobs using GraphComputation`GraphCommunitiesPlotDump`generateBlobs
:
ClearAll[blobF, fC]
fC[pts_, size_: .04] := Module[{}, CommunityGraphPlot[Graph@{}, {}];
GraphComputation`GraphCommunitiesPlotDump`generateBlobs[Automatic, {pts}, size][[2, 1]]]
blobF[g_, cols_, coms_, size_: .04] := Thread[{cols, EdgeForm[{Gray, Thin}], Opacity[.25],
fC[PropertyValue[{g, #}, VertexCoordinates] & /@ #, size] & /@ coms}];
Example:
SeedRandom[1]
data = RandomReal[{0, 1}, {30, 2}];
myadjacencymatrix = Table[If[i != j && Norm[data[[i]] - data[[j]]] < .2, 1, 0],
{i, 30}, {j, 30}];
mygraph = AdjacencyGraph[myadjacencymatrix, VertexCoordinates -> data];
mycliques = ConnectedComponents[mygraph];
mygraph2 = SetProperty[mygraph, {ImagePadding -> 15, VertexLabels -> "Name",
Epilog -> blobF[mygraph, {Cyan, Green, Blue, Orange, Red}, mycliques, .02] }];
Row[Panel /@ {mygraph, mygraph2}]
Original answer:
Graphics`Mesh`MeshInit[];
cC = #[[ConvexHull[#]]]&/@ (PropertyValue[{mygraph, #}, VertexCoordinates] & /@
# & /@ mycliques);
g2 = Graphics[{Opacity[.25], {Hue[RandomReal[]], Polygon[#]} & /@ cC}];
mygraph2 = Show[g2, HighlightGraph[mygraph, Subgraph[mygraph, #] & /@ mycliques]];
Row[{Panel@mygraph, Panel@mygraph2}, Spacer[15]]
Update: Use Scale
to make the polygons larger:
g2b = Graphics[{Opacity[.3], {Hue[RandomReal[]], Scale[Polygon[#], 1.2]} & /@ cC}];
mygraph2b = Show[g2b, HighlightGraph[mygraph, Subgraph[mygraph, #] & /@ mycliques]];
Row[{Panel@mygraph, Panel@mygraph2b}, Spacer[15]]