6
$\begingroup$

Using the Following Network:

footballNetwork = ExampleData[{"NetworkGraph", "AmericanCollegeFootball"}];
Graph[footballNetwork, VertexLabels -> "Name"]

enter image description here


I ranked the top ten nodes based on EigenvectorCentrality, and highlighted those nodes on the network:

HighlightGraph[footballNetwork, Part[VertexList[footballNetwork], Ordering[EigenvectorCentrality[footballNetwork], -10]]]

enter image description here


I know how to label all of the nodes in the network, but how do I label only the nodes that are highlighted?

$\endgroup$
1
  • 1
    $\begingroup$ If ord = Ordering[EigenvectorCentrality[footballNetwork], -10] with Graph[footballNetwork, VertexLabels -> Thread[VertexList[footballNetwork][[ord]] -> VertexList[footballNetwork][[ord]]]] ? $\endgroup$ Jun 13, 2017 at 15:09

2 Answers 2

4
$\begingroup$
t10 = VertexList[footballNetwork][[Ordering[EigenvectorCentrality[footballNetwork], -10]]];

HighlightGraph[footballNetwork, Property[#, VertexLabels -> "Name"] & /@ t10]

or, (thanks: @halmir):

HighlightGraph[footballNetwork, t10, VertexLabels -> "Name"]

to get

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ or you can just do HighlightGraph[footballNetwork, t10, VertexLabels -> "Name"] $\endgroup$
    – halmir
    Jun 14, 2017 at 15:10
  • $\begingroup$ @kglr what does the "& /@" exactly do? $\endgroup$
    – jfeuerman
    Jun 14, 2017 at 17:48
  • $\begingroup$ Thank you @halmir. I updated with your suggestion. $\endgroup$
    – kglr
    Jun 14, 2017 at 21:05
  • $\begingroup$ @JakeFeuerman, see Function (&) and Map (/@) $\endgroup$
    – kglr
    Jun 14, 2017 at 21:06
2
$\begingroup$

Associations are useful for such tasks.

footballNetwork = 
  ExampleData[{"NetworkGraph", "AmericanCollegeFootball"}];

asc = AssociationThread[
   VertexList[footballNetwork], 
   EigenvectorCentrality[footballNetwork]
   ];

Graph[footballNetwork,
 VertexLabels -> Thread[Keys@TakeLargest[asc, 10] -> "Name"]
 ]
$\endgroup$
1
  • 1
    $\begingroup$ I figured it out, sorry :) VertexLabels -> {i -> "Name", j -> "Name"} $\endgroup$
    – user52181
    Apr 9, 2019 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.