16
$\begingroup$

This is more of an abstract/creative problem. I think everyone who has played around with GraphPlot, ended up with an image that looks like this, at least once in their life:

messy GraphPlot output

I am looking for general solutions to convert many connections -> many connections into something that's human understandable.

Here's my code above:

d = DictionaryLookup[RegularExpression["[a-z]{1,5}"]];
d = Take[d, 1000];
g = {};
Do[Do[If[Abs[StringLength[d[[i]]] - StringLength[d[[j]]]] > 1, 
   Continue[]];
  If[EditDistance[d[[i]], d[[j]]] == 1, 
   AppendTo[g, d[[i]] -> d[[j]]];
   AppendTo[g, d[[j]] -> d[[i]]]], {j, i + 1, Length[d]}], {i, 1, 
  Length[d]}]

Needs["GraphUtilities`"]
s = StrongComponents[g];
sc = Last[SortBy[s, Length]];
gc = Select[g, MemberQ[sc, #[[1]]] &];
GraphPlot[gc, 
 EdgeRenderingFunction -> ({Orange, Arrowheads[Small], 
     Arrow[#1, .07]} &)]

I would love something like this, where strongly connected nodes are grouped into single pie-chart vertices which represent the # of node connections over total connections.

$\endgroup$
4
  • $\begingroup$ Your example graph will typically have only a single component of size larger than one, so grouping components into nodes is very likely to just give a star graph in this specific case. $\endgroup$
    – Szabolcs
    Feb 16, 2012 at 11:18
  • $\begingroup$ How about this? $\endgroup$ Feb 16, 2012 at 12:34
  • $\begingroup$ Well, this one is a connected graph (it has a single connected component). My point was that you could get better answers if you made the question more specific. A hairball is a hairball but sometimes it has some underlying structure. What that structure is and how to extract it will be different from network to network ... I think the question is too broad to get good answers. $\endgroup$
    – Szabolcs
    Feb 16, 2012 at 12:51
  • $\begingroup$ There's no generic way to extract the underlying structure? I mean, if you gave me a hairball list of data, I would immediately apply generic metrics like mean / mediam / sdev / mode/ etc. to better understand it. It's not my field, so I was wondering if there are generic solutions to handle that these network graphs in the same way. Like grouping closely related connections, and outputting them as pie-charts as 'strength' meters (immediate vs total connections); Or group and play with transparency (weakly connected are barely visible). $\endgroup$ Feb 16, 2012 at 13:48

1 Answer 1

9
$\begingroup$

Your graph has many vertexes, while the exemplary graph you link to does not and this is why it looks so nice. Styling with pie charts is not a problem at all:

g = RandomGraph[{15, 43}];

vfc[{xc_, yc_}, name_, {w_, h_}] := 
 Inset[PieChart[{VertexDegree[g, name], VertexList[g] // Length}, 
   SectorOrigin -> {Automatic, .7}, 
   ChartStyle -> "AvocadoColors"], {xc, yc}, Automatic, 
  VertexDegree[g, name]/30]

SetProperty[g, VertexShapeFunction -> vfc]

enter image description here

I by the way understand that you want more - to replace "heavy" sub-graphs by nodes reflecting their statistics. That could be done, but it is a bit messy and ambiguous, more of a research question. If I find time I may post a solution.

Here is another angle at a quicker analysis. Automatic spatial layouts Mathematica uses for graph carry a lot of information too. We can use FindClusters to analyse it. I will remove directed and multiple edges for clear picture. To see clustering of regions, after you execute your code do this:

n = 10;(*number of clusters*)
grr = Graph[Union[Sort /@ gc], DirectedEdges -> False, GraphStyle -> 
      "LargeNetwork", VertexSize -> 0];
cls = ListPlot[FindClusters[AbsoluteOptions[grr, VertexCoordinates][[2]], n],
      PlotStyle -> ColorData[3, "ColorList"]];
Show[grr, cls, BaseStyle -> PointSize[.01]]

enter image description here

$\endgroup$
4
  • $\begingroup$ wow looks great! but does this work with GraphPlot? Assuming my Example Graph above is g = GraphPlot[gc] (removed Edge Rendering) and SetProperty[g, VertexShapeFunction -> vfc] $\endgroup$ Feb 17, 2012 at 0:39
  • $\begingroup$ @Mr.DemetriusMichael Graph has much greater functionality than GraphPlot in the sense that GraphPlot is only graphics while Graph holds complete information about the graph itself and can be operated upon with various graph-related functions. I'd recommend to use Graph for 2D graphs. $\endgroup$ Feb 17, 2012 at 2:53
  • $\begingroup$ Might I suggest BaseStyle -> {PointSize[0.01]}, PlotStyle -> Array[ColorData[3], n] $\endgroup$
    – Mr.Wizard
    Feb 17, 2012 at 11:18
  • $\begingroup$ @Mr.Wizard Yes, thanks, should keep it simple ;-) $\endgroup$ Feb 17, 2012 at 11:50

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.