# Vertex Size for more than one vertex

I am pretty sure that the answer to this question is pretty simple, but after googling for several hours in an attempt to find an answer I feel I have to ask someone for help.

I just made my first diagram in Mathematica, however I need different vertex sizes, since the labels are of different lengths:

e = {{M1, W1} -> {M1, M2, W1, W2}, {M1, W2} -> {M1, M2, W1, W2}, {M1,
W3} -> {M1, M3, W3, W4}, {M1, W4} -> {M1, M3, W3, W4}, {M2,
W1} -> {M1, M2, W1, W2}, {M2, W1} -> {M2, M3, W1, W2}, {M2,
W2} -> {M1, M2, W1, W2}, {M2, W2} -> {M2, M3, W1, W2}, {M2,
W3} -> {M2, M3, W3, W4}, {M2, W4} -> {M2, M3, W3, W4}, {M3,
W1} -> {M2, M3, W1, W2}, {M3, W1} -> {M3, M4, W1, W2}, {M3,
W1} -> {M3, M4, W1, W3}, {M3, W1} -> {M3, M4, W1, W4}, {M3,
W2} -> {M2, M3, W1, W2}, {M3, W2} -> {M3, M4, W1, W2}, {M3,
W3} -> {M3, M4, W1, W3}, {M3, W3} -> {M2, M3, W3, W4}, {M3,
W3} -> {M1, M3, W3, W4}, {M3, W4} -> {M3, M4, W1, W4}, {M3,
W4} -> {M2, M3, W3, W4}, {M3, W4} -> {M1, M3, W3, W4}, {M4,
W1} -> {M3, M4, W1, W2}, {M4, W1} -> {M3, M4, W1, W3}, {M4,
W1} -> {M3, M4, W1, W4}, {M4, W2} -> {M3, M4, W1, W2}, {M4,
W3} -> {M3, M4, W1, W3}, {M4, W4} -> {M3, M4, W1, W4}};

Graph[
e,
PerformanceGoal -> "Quality",
DirectedEdges -> True,
VertexLabels -> Placed["Name", Center],
VertexSize -> {0.6,
{M1, M2, W1, W2} -> 0.9, {M1, M3, W3, W4} ->
0.9, {M2, M3, W1, W2} -> 0.9, {M2, M3, W3, W4} ->
0.9, {M3, M4, W1, W2} -> 0.9, {M3, M4, W1, W3} ->
0.9, {M3, M4, W1, W4} -> 0.9},
ImageSize -> 1500,
]


The way I solved it here is pretty inelegant, but I simply do not see how I can assign a vertex size to more than one vertex at a time. Optimally I would like to assign a vertex size according to the Length of the label. Alternatively, I'd be happy to assign the VertexSize to a list. In the documentation for VertexSize, it is done the same way as I have done it here.

One possibility is to use a VertexShapeFunction whose size depends on the length of the vertex name:

Graph[
e,
PerformanceGoal->"Quality",
DirectedEdges->True,
VertexLabels->Placed["Name",Center],
ImageSize->1500,
VertexShapeFunction->Function@{Disk[#, Length[#2]/8.5], Text[#2,#1]}
]


I just used trial and error for the radius.

You can use rules for setting values for the option VertexSize :

Graph[e, VertexSize -> {v_ -> .6, v_ /; Length[v] === 4 -> .9},
PerformanceGoal -> "Quality", DirectedEdges -> True,
VertexLabels -> Placed["Name", Center],
ImageSize -> 1500, BaseStyle -> {"Arrowheads" -> .009}]


Alternatively,

Graph[e, VertexSize -> {v_ :> If[Length[v] === 4, .9, .6]},
PerformanceGoal -> "Quality", DirectedEdges -> True,
VertexLabels -> Placed["Name", Center],
ImageSize -> 1500, BaseStyle -> {"Arrowheads" -> .009}]


same picture

You might also consider an alternative vertex shape that eliminates the need to set vertex sizes explicitly:

Graph[e, PerformanceGoal -> "Quality", DirectedEdges -> True,
VertexShapeFunction -> (Text[Framed[Style[#2, Black], RoundingRadius -> 10,
Background -> LightBlue], #] &),
ImageSize -> 1500]


Clear["Global*"]

e = {{M1, W1} -> {M1, M2, W1, W2}, {M1, W2} -> {M1, M2, W1, W2}, {M1,
W3} -> {M1, M3, W3, W4}, {M1, W4} -> {M1, M3, W3, W4}, {M2,
W1} -> {M1, M2, W1, W2}, {M2, W1} -> {M2, M3, W1, W2}, {M2,
W2} -> {M1, M2, W1, W2}, {M2, W2} -> {M2, M3, W1, W2}, {M2,
W3} -> {M2, M3, W3, W4}, {M2, W4} -> {M2, M3, W3, W4}, {M3,
W1} -> {M2, M3, W1, W2}, {M3, W1} -> {M3, M4, W1, W2}, {M3,
W1} -> {M3, M4, W1, W3}, {M3, W1} -> {M3, M4, W1, W4}, {M3,
W2} -> {M2, M3, W1, W2}, {M3, W2} -> {M3, M4, W1, W2}, {M3,
W3} -> {M3, M4, W1, W3}, {M3, W3} -> {M2, M3, W3, W4}, {M3,
W3} -> {M1, M3, W3, W4}, {M3, W4} -> {M3, M4, W1, W4}, {M3,
W4} -> {M2, M3, W3, W4}, {M3, W4} -> {M1, M3, W3, W4}, {M4,
W1} -> {M3, M4, W1, W2}, {M4, W1} -> {M3, M4, W1, W3}, {M4,
W1} -> {M3, M4, W1, W4}, {M4, W2} -> {M3, M4, W1, W2}, {M4,
W3} -> {M3, M4, W1, W3}, {M4, W4} -> {M3, M4, W1, W4}};

vLong = Cases[e, _List?(Length[#] > 2 &), {2}] // Union;

Graph[e, PerformanceGoal -> "Quality",
DirectedEdges -> True,
VertexLabels -> Placed["Name", Center],
VertexSize -> Flatten[{0.6, Thread[vLong -> 0.9]}],
ImageSize -> 1500,

• Use either VertexStyle -> Directive[White, EdgeForm[White]] or VertexStyle -> {{White, EdgeForm[White]}}` – Bob Hanlon Nov 19 at 21:05