Skip to main content
Tweeted twitter.com/StackMma/status/1198481486380511237
Formatted code
Source Link
MarcoB
  • 67.7k
  • 18
  • 96
  • 198

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 -> 1, 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]]}]

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 -> 1, 
  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]]}]

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 -> 1, 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]]}]

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 -> 1, 
  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]]}]
Source Link
user42700
  • 1.8k
  • 9
  • 14

How to Tailor Community Graph Plot

Below is a graph I've colored with 3 colors Orange, Red, and Green. I would like to generate the community graph plot that uses the colors I've assigned to these nodes and not the default colors the community graph defaults to ... is there a way to control the colors to those I've assigned to the vertices?

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 -> 1, 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]]}]