You can use VertexSize
and VertexStyle
(suggested by Szabolcs in comments) in two ways:
SetProperty[G,
{VertexSize -> Thread[VertexList[G] -> ls],
VertexStyle -> Thread[VertexList[G] -> (ColorData["Rainbow"] /@ Rescale[ls])]}]
or
SetProperty[G,
{VertexSize -> {v_ :> ls[[v]]},
VertexStyle -> {v_ :> (ColorData["Rainbow"]@Rescale[ls][[v]])}}]
You can rescale ls
to make the vertices with weight 0 more visible
G2 = SetProperty[G,
{VertexSize -> {v_ :> Rescale[ls[[v]], MinMax @ ls, {.1, 1}]},
VertexStyle -> {v_ :> (ColorData["Rainbow"] @ Rescale[ls][[v]])}}]
and add a legend with markers showing both colors and relative sizes:
legendLayout = Framed[#, FrameStyle -> None] &@
Grid[Prepend[MapIndexed[{#2[[1]], #[[1]], Item[#[[2]],
Alignment -> {Decimal, Center}]} &, #],
Item[Style[#, 14], Background -> LightBlue, Alignment -> {Center, Center}] & /@
{"vertex", "color", "weight"}],
Alignment -> {Center, Center},
Dividers -> {None, {1 -> True, 2 -> True, -1 -> True}}] &;
legend = SwatchLegend[ColorData["Rainbow"] /@ Rescale[ls], ls,
LegendMarkers -> Thread[{"Bubble", Rescale[ls, MinMax@ls, {5, 25}]}],
LegendLayout -> legendLayout];
Legended[G2, legend]
You can also use GraphComputation`GraphPropertyChart
to get a circular bar chart showing ls
as vertex properties:
GraphComputation`GraphPropertyChart[G,
Automatic -> Rescale[ls, MinMax @ ls, {.05, 1}],
ColorFunction -> "Rainbow",
ChartLegends -> legend]
Using it with a custom ChartElementFunction
:
cEF[{{t0_, t1_}, {r0_, r1_}}, ___] := Disk[r1 {Cos[(t0 + t1)/2], Sin[(t0 + t1)/2]},
Pi Abs[t1 - t0]]
GraphComputation`GraphPropertyChart[G,
Automatic -> Rescale[ls, MinMax@ls, {.05, 1}],
ColorFunction -> "Rainbow", ChartLegends -> legend,
ChartElementFunction -> cEF, ChartLabels -> {},
LabelingFunction -> (Placed[Style[#2[[2]], 16], #2[[2]] /.
{4 | 9 | 13 -> "RadialCallout", 12 -> "RadialOutside", _ -> "RadialEdge"}] &),
ImagePadding -> 35, ImageSize -> 500]
VertexSize
andVertexStyle
? $\endgroup$