# Plotting attributes of vertices in WattsStrogatzGraphDistribution[n, p, k]

I have a graph WS = RandomGraph[WattsStrogatzGraphDistribution[n, p, k]]. I need to plot several characteristics of each v: the clustering coefficient, number of triples at v, eccentricity, vertex centrality, closeness, and betweenness. I'm relatively inexperienced with Mathematica and quite lost on how to achieve this. I don't expect the exact lines of the solution, I'd just like some pointers on how to approach this. First of all, how do I get a set of all the vertices of WS? Then, how do I get the values of the different measures for each v in WS?

Update: Using GraphComputationGraphPropertyChart for displaying vertex attributes:

SeedRandom
ws = RandomGraph[WattsStrogatzGraphDistribution[6, 0.6, 2]];
centralities = {LocalClusteringCoefficient, EccentricityCentrality,
VertexDegree, ClosenessCentrality, BetweennessCentrality,  EigenvectorCentrality};
Through[centralities[ws]] //
Style[TableForm[Round[#, .001], TableHeadings -> {centralities, VertexList[ws]}],
FontFamily -> "Calibri", 24] & Legended[GraphComputationGraphPropertyChart[RemoveProperty[ws, VertexLabels],
Automatic -> (#[ws] + .1),
ImageSize -> 300, ChartStyle -> 63],
Placed[Style[#, 20, "Panel"], {1/2, 97/100} ]] & /@
centralities /. False -> True //
Partition[#, 3] & // Grid Using the built-in functions mentioned in @Oska's comment:

ws = RandomGraph[WattsStrogatzGraphDistribution[6, 0.1, 2]];
centralities = {LocalClusteringCoefficient,  EccentricityCentrality,
VertexDegree, ClosenessCentrality, BetweennessCentrality};
Through[centralities[ws]] // Style[TableForm[Round[#, .001],
TableHeadings -> {centralities, VertexList[ws]}], FontFamily -> "Calibri", 24] & • Interesting choice of font. – m_goldberg May 10 '14 at 18:50
• @m_goldberg, Office 2010 default font family:) – kglr May 10 '14 at 18:58
• @bhkj I only Googled what you typed. See here and here. – Öskå May 11 '14 at 16:02
• @bhkj, glad it was useful for you. Thanks for the accept. – kglr May 11 '14 at 16:22

There's one measure you were asking for missing from the existing answer:

number of triples at v

This can be obtained efficiently using IGraph/M's IGAdjacentTriangleCount function.

?IGAdjacentTriangleCount


IGAdjacentTriangleCount[graph] counts the triangles each vertex participates in. Edge directions are ignored.

IGAdjacentTriangleCount[graph, vertex] counts the triangles vertex participates in.

IGAdjacentTriangleCount[graph, {vertex1, vertex2, ...}] counts the triangles the specified vertices participate in.

It can also be implemented in pure Mathematica very concisely (though less efficiently) using the fact that if $A$ is the graph's adjacency matrix, then $(A^k)_{ij}$ contains the number of ways we can get from vertex $i$ to vertex $j$ in $k$ hops. Thus $(A^3)_{ii}$ gives twice the number of triangles that $i$ participates in (twice because the triangle, i.e. 3-loop, can be traversed in two directions).

g = RandomGraph[{10, 20}];

(* {0, 4, 3, 7, 5, 6, 0, 9, 0, 2} *)

Normal@Diagonal[am.am.am]/2
]
(* {0, 4, 3, 7, 5, 6, 0, 9, 0, 2} *)


As for visualizing these, these days I much prefer doing this with IGraph/M (disclosure: I'm the author). Here's a simple example:

RandomGraph[WattsStrogatzGraphDistribution[20, 0.2]] //
IGVertexMap[ColorData["SolarColors"], VertexStyle -> Rescale@*BetweennessCentrality] The measures you are asking for are available as the following builtin an IGraph/M functions:

• clustering coefficient: LocalClusteringCoefficient, IGLocalClusteringCoefficient

• number of triples: IGAdjacentTriangleCount

• eccentricity: VertexEccentricity (for one vertex), EccentricityCentrality (inverse), IGEccentricity

• vertex centrality: I don't know what you mean

• closeness: ClosenessCentrality, IGCloseness, IGClosenessEstimate (for big graphs)

• betweenness: BetweennessCentrality, IGBetweenness, IGBetweennessEstimate (for big graph)

Here's a nicer plot of all of them, also showing off IGWattsStrogatzGame, which supports some additional features not available with WattsStrogatzGraphDistribution.

g = IGWattsStrogatzGame[20, 0.2, GraphLayout -> "CircularEmbedding", VertexSize -> Large, GraphStyle -> "BasicBlack"]

Labeled[IGVertexMap[ColorData["Rainbow"], VertexStyle -> Rescale@*#, g], #] & /@ 