I would like to visualize separate connected components of a graph defined by data points lying in the two-dimensional plane by surrounding each connected component subgraph by a bounding curve. I can almost render such a figure using CommunityGraphPlot[]
, except that the vertexes do not remain in their two-dimensional location as I desire.
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];
My attempt at a "trick" is to find the subgraphs by ConnectedComponents[]
and call them cliques, so they can be used in CommunityGraphPlot[]
.
mycliques = ConnectedComponents[mygraph];
CommunityGraphPlot[mygraph, mycliques, CommunityRegionStyle -> Opacity[0.1]]
The resulting plot shows the topological relations of the vertexes and bounding curves I need, but the vertexes are no longer in their specified original two-dimensional positions. I've tried VertexCoordinates -> data
, but that doesn't work.
Perhaps one could set a Property
of a vertex to be its spatial location to ensure each is rendered in its proper two-dimensional location, but I do not see how to do that.
One can use HighlightGraph[mygraph, mycliques] but that merely shows the links, not a bounding curve. Is rendering a bounding curve impossible in the general case because some subgraphs might require a concave bounding curve, when only convex bounding curves can be drawn?
Any suggestions?