4
$\begingroup$

From the communities formed by the code below, I generate a row containing the subgraphs of each community. For each subgraph in that row, how can I build the following table: Column 1 lists all the vertexes in that subgraph. Column 2 shows the color that vertex had in its subgraph. Column 2 could be a list of colored squares (say) that matches the color of its vertex in that subgraph.

edges = {NS <-> N1, NS <-> N11, NS <-> N18, NS <-> N24, NS <-> N27, 
   NS <-> N35, NS <-> N37, N1 <-> N4, N1 <-> N5, N1 <-> N6, N1 <-> N7,
    N1 <-> N8, N1 <-> N9, N2 <-> N5, N3 <-> N5, N3 <-> N15, N4 <-> N2,
    N4 <-> N3, N4 <-> N5, N4 <-> N12, N4 <-> N13, N4 <-> N14, 
   N5 <-> N15, N5 <-> N16, N5 <-> N19, N6 <-> N15, N7 <-> N10, 
   N8 <-> N16, N9 <-> N10, N10 <-> N5, N10 <-> N6, N10 <-> N8, 
   N11 <-> N6, N11 <-> N8, N11 <-> N21, N12 <-> N17, N12 <-> N40, 
   N13 <-> N6, N13 <-> N21, N14 <-> NG, N15 <-> N30, N16 <-> N6, 
   N17 <-> NG, N18 <-> N15, N19 <-> N20, N20 <-> N21, N20 <-> N30, 
   N21 <-> N22, N22 <-> N23, N22 <-> N43, N23 <-> NG, N24 <-> NG, 
   N25 <-> NG, N26 <-> N29, N26 <-> N40, N27 <-> N28, N27 <-> N40, 
   N28 <-> NG, N29 <-> NG, N30 <-> N31, N30 <-> N32, N30 <-> N33, 
   N30 <-> N34, N31 <-> N36, N32 <-> N36, N33 <-> N36, N34 <-> N31, 
   N35 <-> N34, N36 <-> N12, N36 <-> N39, N37 <-> N36, N38 <-> N40, 
   N38 <-> N43, N39 <-> N40, N40 <-> N41, N41 <-> N42, N42 <-> NG, 
   N43 <-> N25, N43 <-> N26, N36 <-> N38};

g = Graph[edges, VertexLabels -> "Name", VertexLabels -> Automatic, 
  VertexSize -> 0.7, 
  VertexStyle -> {NS | N1 | NS | N11 | NS | N18 | NS | N24 | NS | 
      N27 | NS | N35 | NS | N37 | N1 | N4 | N1 | N5 | N1 | N6 | N1 | 
      N7 | N1 | N8 | N1 | N9 | N2 | N5 | N3 | N5 | N3 | N15 | N4 | 
      N2 -> Red, 
    N4 | N3 | N4 | N5 | N4 | N12 | N4 | N13 | N4 | N14 | N5 | N15 | 
      N5 | N16 | N5 | N19 | N6 | N15 | N7 | N10 | N8 | N16 | N9 | 
      N10 | N10 | N5 | N10 | N6 | N10 | N8 | N11 | N6 | N11 | N8 | 
      N11 | N21 | N12 | N17 | N12 | N40 | N13 | N6 | N13 | N21 | N14 |
       NG | N15 | N30 | N16 | N6 | N17 | NG | N18 | N15 | N19 | N20 | 
      N20 | N21 | N20 | N30 | N21 | N22 | N22 | N23 | N22 | N43 | 
      N23 | NG | N24 | NG | N25 | NG | N26 | N29 | N26 | N40 -> Green,
     N28 | NG | N29 | NG | N30 | N31 | N30 | N32 | N30 | N33 | N30 | 
      N34 | N31 | N36 | N32 | N36 | N33 | N36 | N34 | N31 | N35 | 
      N34 | N36 | N12 | N36 | N39 | N37 | N36 | N38 | N40 | N38 | 
      N43 | N39 | N40 | N40 | N41 | N41 | N42 | N42 | NG | N43 | N25 |
       N43 | N26 | N36 | N38 -> Lighter[Lighter[Orange]]}]

cg = CommunityGraphPlot[g, 
  VertexStyle -> PropertyValue[g, VertexStyle]]
AA = FindGraphCommunities[g];
Row[Subgraph[g, #, VertexLabels -> "Name", 
    VertexStyle -> PropertyValue[g, VertexStyle]] & /@ AA]
$\endgroup$
4
$\begingroup$
subgraphs = Subgraph[g, #, VertexLabels -> "Name", ImageSize -> 200, 
     VertexStyle -> {v_ :> PropertyValue[{g, v}, VertexStyle]}] & /@ AA;

labels = Grid[SortBy[First][List @@@ PropertyValue[#, VertexStyle]]] & /@ subgraphs;

Row[MapThread[Labeled[##, Right] &, {subgraphs, labels}], Spacer[5]]

enter image description here

$\endgroup$
  • $\begingroup$ Wow ... is there a way to SORT each list by Vertex name? or is there way to order the list by colors (say,Red first, then Orange, then Green?) $\endgroup$ – PRG Dec 21 '19 at 1:24
  • $\begingroup$ @PRG, please see the updated version. $\endgroup$ – kglr Dec 21 '19 at 1:30
  • $\begingroup$ many thanks for your help. I've learned alot ... regards ... prg $\endgroup$ – PRG Dec 21 '19 at 1:35
  • $\begingroup$ @PRG, my pleasure. Thank you for accepting. $\endgroup$ – kglr Dec 21 '19 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.