# VertexSize doesn't scale with Graph layout?

I wonder about how I could make a Graph scale automatically when I vary the size of the vertices.

I would like to visualize information with a Graph. The vertices all have e.g. additional info like a weight which I would like to visualize with the vertices drawn with different sizes.

However, when I define the sizes, the graph keeps the original (as opposed to the new) layout. The graph then becomes invisible.

Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3,3 \[UndirectedEdge] 1, 3 \[UndirectedEdge] 4}]


shows: Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3,3 \[UndirectedEdge] 1, 3 \[UndirectedEdge] 4},VertexSize -> {1 -> 1.1, 2 -> 1.2, 3 -> 1.3, 4 -> 1.4}]


This shows: What I would like is that the Graph would be like Any thoughts?

This is a graph currently working on. As you can see one vertex hits his neighbour. I would expect MM to or reposition this vertex a bit further or to scale down all nodes. Of course this can be done by dividing the vertexes by a number. But this is manual work to see what looks best. I hope there is another way. • How about Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1, 3 \[UndirectedEdge] 4}, VertexSize -> {1 -> {"Scaled", 1.1/15}, 2 -> {"Scaled", 1.2/15}, 3 -> {"Scaled", 1.3/15}, 4 -> {"Scaled", 1.4/15}}]? – J. M.'s discontentment Jan 20 '12 at 14:49
• I've considered this solution but if the difference between the weights is high (eg 20 vertexes with weight 10 against 1 with 100 will draw the large vertex on top of other neighbouring vertexes. I hope somebody knows an option that might trigger the plotting of graph after considering the vertex sizes.. – Lou Jan 20 '12 at 15:14

Does the following do what you want?

WeightedGraph[edges_, weights_, options___]:=
Block[{maxweight=Max[#[]&/@weights]},
Graph[edges,VertexSize->((#[]->0.9*#[]/maxweight)&/@weights),options]]

WeightedGraph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3,
3 \[UndirectedEdge] 1, 3 \[UndirectedEdge] 4},
(*weights:*) {1 -> 1.1, 2 -> 1.2, 3 -> 1.3, 4 -> 1.4}] The second line is basically your Graph call, except that it uses WeightedGraph instead of Graph, and the weights don't have VertexSize-> in front of them.

• Great this works. Uses the Max instead of the average is the thing to go for. The fixed value 0.9 scales best indeed. – Lou Jan 21 '12 at 21:44

Your second figure indicates that you'd like each consecutive vertex to be twice the size of the previous one, yet the weights you added won't achieve that. Here's one way of doing what you want:

Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3,
3 \[UndirectedEdge] 1, 3 \[UndirectedEdge] 4},
VertexSize -> {1 -> 0.1, 2 -> 0.2, 3 -> 0.3, 4 -> 0.4}] Now coming to why your weights made the vertices cover the entire page, and not scale correctly, the documentation for VertexSize notes that VertexSize->s for a number s is taken to be VertexSize->{"Nearest",s}, where {"Nearest",s} is a fraction of the minimum distance between the vertex coordinates.

In this case, the minimum distance is between nodes 1 and 2, hence setting VertexSize->1 is equivalent to setting the diameter of the circle to be the same as the node distance between 1 and 2.

This is perhaps clearer from the following example:

FullGraphics@GraphicsRow@
Table[CompleteGraph[8, VertexSize -> s, PlotLabel -> s], {s, 0.1, 1, 0.3}] • thx. The example is great but what I mean is perhaps not clear enough. Suppose one of the vertexes is now say 300% larger. That vertex will still overwrite the other vertexes. I added in my question a graph I'm working on. – Lou Jan 20 '12 at 15:42