1
$\begingroup$

I would like to scale the nodes in a network according to various properties of those nodes. It's a fairly common thing to do with networks, but Mathematica's Graph functionality doesn't seem to support it well. This was partially addressed 4 years ago and what seemed to be an answer here, but it doesn't work quite as needed...especially for larger graphs.

First I create a random graph and scale the degrees of each node on a 1 to 10 scale.

TestGraph = RandomGraph[{1000, 2000}];
VertexDegrees = Rescale[VertexDegree@TestGraph,Min[VertexDegree@TestGraph],
  Max[VertexDegree@TestGraph]}, {1, 10}];
VertexSizeRules = Thread[VertexList@TestGraph -> VertexDegrees];

Then I plot using those as the VertexSize rules:

GraphDrawing = SetProperty[TestGraph, VertexSize -> VertexSizeRules]

First test plot

What I expected to see is that the largest degree node is 10 times larger than the smallest degree nodes. That is clearly not happening.

Now, if I specify an ImageSize for the graph rendering, it's even worse:

GraphDrawing = SetProperty[GraphDrawing, ImageSize -> 600]

enter image description here

Still there is no variation in the node sizes based on degree, but also the nodes aren't even as large as the edge layout thinks they are. Note that this "edge not touching the nodes" happens if all nodes have a fixed "Scaled" size as explained in the documentation (and it gets further away with larger vertex sizes but the dot stays the same size).

So the first question is: How does one get the nodes to scale as expected from some base size up to 10 times that base size depending on a node property?

The second question is: How does one get that to render correctly when the ImageSize is specified?

$\endgroup$
2
$\begingroup$

Mathematica automatically set vertex shape to point when graph is large. You can reset vertex shape to "Circle":

GraphDrawing = 
 SetProperty[
  TestGraph, {VertexSize -> VertexSizeRules, 
   VertexShapeFunction -> "Circle", ImageSize -> 600}]
$\endgroup$

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.