I'd prefer the method in @halmir's answer, but using Style
wrapper on the second argument of CommunityGraphPlot
does not work in Version 9.0.1.0 (Windows 8 64bit). An alternative is to use VertexStyle
with some pre-processing:
ClearAll[cgpF];
cgpF[g_Graph, coms_: Automatic,
cols_: GraphComputation`GraphInformationDump`$AutomaticColorList,
opts : OptionsPattern[CommunityGraphPlot]] :=
Module[{gc = If[coms === Automatic, FindGraphCommunities[g], coms],vs, t},
t = Thread[{gc, PadRight[cols, Length@gc, cols]}];
vs = Join @@ (Function[{v, c}, # -> c & /@ v] @@@ t);
CommunityGraphPlot[g, gc, VertexStyle -> vs, opts]];
Examples:
g1 = ExampleData[{"NetworkGraph", "DolphinSocialNetwork"}];
cgpF[g1]
cgpF[g1, Automatic, cl = ColorData[43, "ColorList"], VertexSize -> 1,
CommunityRegionStyle -> (Directive[EdgeForm[{Thickness[.01], Lighter[#, .4]}],
Lighter[#, .7]] & /@ cl)]
randomcommunities = Internal`PartitionRagged[VertexList[g1],
RandomChoice[IntegerPartitions[VertexCount[g1], {4}]]];
cgpF[g1, randomcommunities, cl = {Red, Cyan, Orange, Green}, VertexSize -> 1.5,
CommunityRegionStyle -> (Directive[{EdgeForm[{Thickness[.01], Lighter[#, .4]}],
Opacity[.2], #}] & /@ cl)]