Wolfram Research

Major League Baseball Teammate Graph 1900-2019

A graph of Major League Baseball players connected by common teams

Details

Each vertex in the graph represents a player.
Each edge in the graph represents a year in which the two connected players played on the same team.
The data was collected from the roster data at baseball-reference.com.
To avoid ambiguity vertex names are Baseball-Reference player ids, the players names are included as "Player" values in the AnnotationRules.
The team name and year is included in the EdgeTags as a Hyperlink to the corresponding Baseball-Reference page.
The graph has 17,669 edges representing players joined by 2,035,808 edges representing common teams.

(17669 vertices, 2035808 edges)

Examples

Basic Examples (4) 

Get the graph:

In[1]:=
graph = ResourceData[\!\(\*
TagBox["\"\<Major League Baseball Teammate Graph 1900-2019\>\"",
#& ,
BoxID -> "ResourceTag-Major League Baseball Teammate Graph \
1900-2019-Input",
AutoDelete->True]\)]
Out[1]=

Get twenty random player ids:

In[2]:=
ids = RandomSample[VertexList[graph], 20]
Out[2]=

Get their names:

In[3]:=
AnnotationValue[{graph, ids}, "Player"]
Out[3]=
In[4]:=
EdgeTags[RandomSample[EdgeList[graph], 20]]
Out[4]=

Find the players connecting the first two ids randomly chosen above:

In[5]:=
AnnotationValue[{graph, FindShortestPath[graph, ids[[1]], ids[[2]]]}, "Player"]
Out[5]=

Scope & Additional Elements (2) 

Create a function to write stories about the connection between any two players:

In[6]:=
WriteStory[g_, {v1_, v2_}] := WriteStory[g, v1, v2]
WriteStory[g_, v1_, v2_] := Block[{path = FindShortestPath[g, v1, v2], names, teams},
  names = AnnotationValue[{g, path}, "Player"];
  names = MapThread[
    Hyperlink[#1, URLBuild[{"https://www.baseball-reference.com/players/", StringTake[#2, 1], #2 <> ".shtml"}]] &, {names, path}];
  teams = First /@ MovingMap[EdgeTags[g, #] &, path, 1];
  Column[{Style[
     Row[{"Connecting ", names[[1]], " and ", names[[-1]]}], 20],
    Row[ReplacePart[
      Riffle[Riffle[names, teams], {" who played on the ", " with "}],
       2 -> " played on the "]]}]
  ]
In[7]:=
WriteStory[ResourceData[\!\(\*
TagBox["\"\<Major League Baseball Teammate Graph 1900-2019\>\"",
#& ,
BoxID -> "ResourceTag-Major League Baseball Teammate Graph \
1900-2019-Input",
AutoDelete->True]\)], "ruthba01", "troutmi01"]
Out[7]=

Create random stories:

In[8]:=
RandomStory[g_] := WriteStory[g, RandomSample[VertexList[g], 2]]
In[9]:=
RandomStory[ResourceData[\!\(\*
TagBox["\"\<Major League Baseball Teammate Graph 1900-2019\>\"",
#& ,
BoxID -> "ResourceTag-Major League Baseball Teammate Graph \
1900-2019-Input",
AutoDelete->True]\)]]
Out[9]=

Wolfram Research, "Major League Baseball Teammate Graph 1900-2019" from the Wolfram Data Repository (2021) 

License Information

https://www.sports-reference.com/data_use.html

Data Resource History

Source Metadata

Publisher Information