How to extract vertex/community colors from FindCommunityPlot

How can I extract the colors of the individual vertices/communities from a community graph plot? E.g.

g = RandomGraph[{20, 40}];
CommunityGraphPlot[g]


I would like to plot each vertex number with its respective community-graph plot-color in another plot. So far, I was able to get a list of the vertices in the respective communities with FindGraphCommunities[g]. How can I continue from here?

By employing

foundCommunities = FindGraphCommunities[g]
communityColors = GraphComputationGraphInformationDump$AutomaticColorList Table[Thread[foundCommunities[[i]] -> communityColors[[i]]], {i, 1,Length@foundCommunities}]  I get {1->Hue[0, 1, 0.8], 5->Hue[0, 1, 0.8], ...}, {10->Hue[0.14, 1, 0.9],...},...}  which I can use in a different plot. • Can you explain the use case (within the question itself)? Do you need to use these colours in a legend? May 15, 2017 at 12:20 • I am wondering what you are using this function for. May 15, 2017 at 12:37 • I want to use the colors associated with the individual vertex numbers in a different plot. May 15, 2017 at 13:11 1 Answer Edited based on @halmir's comment. You can specify the colours manually by wrapping the community specifications in Style[..., colour]. For example, g = RandomGraph[{10, 20}] communities = FindGraphCommunities[g] (* {{4, 6, 7, 8, 10}, {1, 2, 9}, {3, 5}} *) CommunityGraphPlot[g, MapThread[Style, {communities, ColorData[81] /@ Range@Length[communities]}]]  Let us also evaluate the MapThread[...] separately to see what the community specification should look like. MapThread[Style, {communities, ColorData[81] /@ Range@Length[communities]}]  Or in InputForm: {Style[{4, 6, 7, 8, 10}, Hue[0.58, 1, 0.5]], Style[{1, 2, 9}, Hue[0.12, 1, 0.9]], Style[{3, 5}, Hue[0, 1, 0.75]]}  Where do the default colours come from? CommunityGraphPlot uses HighlightGraph under the hood to highlight the vertices. HighlightGraph uses the following internal colour function: GraphComputationGraphInformation["DefaultGroupColorFunction"]  This colour function takes the colours periodically from the following list: GraphComputationGraphInformationDump$AutomaticColorList


For reference, in version 11.1.1 that is

{Hue[0, 1, 0.8], Hue[0.14, 1, 0.9], Hue[0.8, 0.6, 0.8], Hue[0.07, 1, 1],
Hue[0.2, 1, 0.6], Hue[0.1, 0.6, 0.7], Hue[0.5, 1, 0.7]}
`

If you want to re-use the colours in another place (for example add a legend), the cleanest solution is to specify the colours manually, as in the first example I showed.

• you could specify color of community by wrapping groups with Style: CommunityGraphPlot[g, {Style[{4, 5, 7, 1, 2}, Green],Style[ {3, 6, 9, 8},Red]}] May 15, 2017 at 13:59
• @halmir Thank you. May 15, 2017 at 15:11