2
$\begingroup$

Is there any way of scaling the sizes of the vertices of a network proportional to the vertex-degrees of the vertices in Mathematica? Thanks.

$\endgroup$
1
7
$\begingroup$
SeedRandom[5]
g = RandomGraph[{6, 10}]

Mathematica graphics

vd = Thread[VertexList@g -> Normalize[VertexDegree@g, Total]];
g2 = SetProperty[g, VertexSize -> vd]

Mathematica graphics

$\endgroup$
6
  • $\begingroup$ Great! Why are you dividing by 20 here? $\endgroup$
    – dbm
    May 6 '16 at 18:21
  • $\begingroup$ @dbm, dividing by 20 was to scale the vertex sizes. It is removed in the updated post. $\endgroup$
    – kglr
    May 6 '16 at 18:26
  • $\begingroup$ Got it. However, this code doesn't work for say g = RandomGraph[{90, 120}] $\endgroup$
    – dbm
    May 6 '16 at 18:29
  • $\begingroup$ @dbm, maybe you can use Normalize[VertexDegree@g, Max] for large graphs. $\endgroup$
    – kglr
    May 6 '16 at 18:33
  • 1
    $\begingroup$ @dbm, it is because when we normalize by Total each vertex degree divided by Total[VertexDegree@g] (240) gives a very small vertex size. If we normalize by Max each vertex degree is divided by 7 (maximum of the vertex degrees). Alternatively, instead of Normalize[...], you can use Rescale[VertexDegree@g, Through[{Min, Max}[VertexDegree@g]], {a, b}] with your choice of a and b. $\endgroup$
    – kglr
    May 6 '16 at 18:44

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.