# Visualising assortativity in networks

Assortativity and disassortativity are graph properties that represent how hub-and-spoke-like a graph is, where assortative graphs have hubs that connect to each other, while disassortative graphs have hubs which tend to connected only to low degree nodes (see the figure below).

Seeing a transition visually from assortativity to disassortativity can be important. Can Mathematica do this with a graph layout that highlights these features?

• I think you should specify more precisely what exactly you want. For example, if you just want to color the vertices by ther degree, you can use g = UndirectedGraph[RandomTree[15], GraphLayout -> "SpringElectricalEmbedding"]; GraphPlot[g, VertexSize -> 1/2, VertexStyle -> Thread[VertexList@g -> ColorData["SiennaTones"] /@ (1 - Normalize[VertexDegree@g, Max])]] But if you actually want the algorithm to decide whether the network is assortative or disassortative, you should check GraphAssortativity. Commented Oct 20, 2023 at 13:09
• I suppose I'm looking for a graph layout that will provide some good visualization of assortativity. Maybe colouring the edges based on the correlation of the degree of their endpoints might be good.
– apg
Commented Oct 20, 2023 at 13:19
• In that case, please include an example of your graph in the question. Commented Oct 20, 2023 at 13:57
• Just a random graph is fine, for example RandomGraph[BarabasiAlbertGraphDistribution[100, 4]]
– apg
Commented Oct 20, 2023 at 14:45

For the style, you could do the following:

g = ExampleData[{"NetworkGraph", "ZacharyKarateClub"}];

vdeg = VertexDegree[g];
vstyle1 =
Blend[{Orange, Darker[Red]}, #] & /@ Rescale[VertexDegree[g]];
vstyle2 =
Blend[{LightBlue, Darker[Blue]}, #] & /@ Rescale[VertexDegree[g]];
hdeg = Pick[VertexList[g], vdeg,
Alternatives @@ Keys[KeySort[Counts[vdeg]][[-4 ;;]]]];

Row[Graph[g,
BaseStyle -> {Opacity[1], Thickness[.006], Black,
EdgeForm[{Opacity[1], Thickness[.006]}]},
VertexStyle -> Thread[VertexList[g] -> #],
VertexLabels ->