top of page
Writer's pictureYash Sakhuja

Tableau: Partnership Graphs in Cricket

My previous blogs on creating Worm and Manhattan charts for cricket received tremendous appreciation from cricket analysts, and I am truly grateful for the messages I received about how these blogs helped them build visualisations tailored to their needs. In this blog, we’ll explore another impactful cricket visualisation—the partnerships graph. This chart illustrates various batting partnerships in an innings, highlighting the run contributions from each partner. Together, we’ll create a partnerships graph in Tableau, aiming for a design similar to the image below, but with a subtle modifications that enhance the story it conveys. I’ll keep the modifications a secret for now, so you can ponder how our version differs from the one shown below.


ESPNCricinfo: Partnerships Graph
ESPNCricinfo: Partnerships Graph

Here's the version in Tableau if you'd like to reverse engineer it first and give it a go by trying and putting your Tableau skills to the test.


Tableau: Partnerships Graph
Tableau: Partnerships Graph

Before moving to Tableau, we should review our data to confirm that we have the required fields in the appropriate format for this visualisation. I utilized data extracted from the ESPN Cricinfo page for the Lancashire vs Surrey, 2nd Quarter Final Match of the Vitality Blast, 2023. For information on how this data was extracted, see the detailed blog on the web scraping process I discussed with CJ Mayes. Subsequently, I ran the data through an additional feature engineering script to generate features for our visualisation. Here is the GitHub repository for the additional pre-processing script.


Data Columns in the Pre-Processed Data
Data Columns in the Pre-Processed Data

Now, let's dive right in and begin constructing a partnership graph in Tableau using less than 10 calculations, along with some techniques to properly position elements on the axis.


Step 1: Adding Labels to either sides for Partner Contributions


a) Add a Teams filter for just looking at the graphs for one team's (Lancashire in the case) Batting


b) Include the Partnership Key Name as a unique row identifier for the Partnerships on Rows in Tableau to ensure each partnership has a single row. Sort the Partnership Key Name by Partnership Key in ascending order, using aggregation as Minimum.


Partnership Key and Partnership Key Name
Partnership Key and Partnership Key Name

c) Create these calculations for identifying Partner 1 and Partner 2 from Partnership Key Name, and their runs scored and balls faced for the labels:

// Partners
REPLACE(REPLACE(REPLACE([Partnership Key Name],"(",""),")",""),"'","")

// Partner1
TRIM(SPLIT([Partners],",",1))
// Partner 1 Runs
SUM(IF [On Strike Batter]=[Partner1] THEN [Bat Runs] END) 
// Partner 1 Balls Faced
COUNTD(IF ([On Strike Batter]=[Partner1]) AND ([Wide Runs]=0) THEN [Ball ID] END)

// Partner2
TRIM(SPLIT([Partners],",",2))
// Partner 2 Runs
SUM(IF [On Strike Batter]=[Partner2] THEN [Bat Runs] END) 
// Partner 2 Balls Faced
COUNTD(IF ([On Strike Batter]=[Partner2]) AND ([Wide Runs]=0) THEN [Ball ID] END)

d) Add two column axes as pills on columns with MIN(1) on columns as Text marks and Partner 1 related information- Name, Runs, and Balls Faced (to the left) and Partner 2 and related information (to the right) to texts on both pills.


e) Hide the Partnership Key Name as header and make necessary formatting changes and you have the labels.


Step 1: Adding labels to either side for Partner Contributions
Step 1: Adding labels to either side for Partner Contributions

Step 2: Adding Bars for both Batters Run Contributions


a) Add 2 column axes as MIN(0) in between the two label MIN(1) axes for the bars.


b) Set the mark type to Gantt bars from the marks pane, and use Partner 1 Runs and Partner 2 Runs as the Size on the marks pane for the two axes on the marks bar, respectively.


c) Reverse the axis on the left and edit the axis and make sure both the axes are ranged from 0 to the same Fixed End (35 here as shown in image below) to ensure both are on the same scale to look aligned.


d) Add Measure Names to color for both the marks and change the colors accordingly.


Step 2: Adding Bars for both Batters Run Contributions
Step 2: Adding Bars for both Batters Run Contributions

Step 3: Making the Bars with Rounded Ends


In order to have these runs contribution bars have rounded ends, let's imagine how these rounded ends work. The bars are rounded at their ends so at the point which is essentially, the total runs scored by the Partner 1 or 2 in that partnership.


a) Add Partner 1 Runs and Partner 2 Runs as continuous measure right before MIN(0) pills and change the marks to circles


b) Synchronise Partner 1 Runs Axis Partner 2 Runs Axis to the subsequent MIN(0) to their right and make sure they're both are ranged from 0 to fixed custom maximum (based on graphs).


c) Add colors to the measure names, same as above, and update colors accordingly.


d) Adjust the size of the circles to match it as the line ends for the bars.


Step 3: Making the Bars with Rounded Ends
Step 3: Making the Bars with Rounded Ends

Additional Formatting


Voila! You now have something resembling the figure shown above. Next, we just need to make some formatting adjustments to enhance its visual appeal. Follow the steps formatting steps below:


a) Hide the axes headers, row and column dividers, and zero lines.


b) Place the Total Partnership Labels at the center of each bar as Mark Annotations, formatting and aligning them to the middle.


Note: The ball counts shown for the total partnership on Cricinfo do not include runs from wides, and the "*" symbol indicates the final not out partnership where both batting partners remain not out.


To create these, you can develop two additional calculations, making your version closely resemble the one from Cricinfo.

// * Calculation
{ FIXED [Team],[Partnership Key Name]: MAX(IF [Ball ID]={ FIXED [Team]:MAX([Ball ID])} AND CONTAINS([Score],"W")==FALSE
THEN "*"END)}

// Excluding Wides Count
COUNTD(IF ([Wide Runs]=0) THEN [Ball ID] END)


b) Format the tooltips.



Here's the final output representation after the additionall formatting has been applied.


Additional Formatting
Additional Formatting

Modifications


If you carefully compared our version with the one from CricInfo. you'd have found two differences between how the graphs are laid out. If you haven't already guessed it, these slight variations are:


1) Our graphs are centered at zero, emphasizing player contributions and enhancing readability.


2) The sequence of players in the partnerships is arranged so that the outgoing batter is replaced by the next batter, clearly illustrating the progression of the match.


Kindly let me know your opinions on these modifications and whether they enhanced your understanding of the graph. A special thanks to CJ Mayes for providing his valuable feedback on these modifications.


If you've read this far and found the blog post helpful, please consider leaving a like or a comment. Let me know how I can make these posts even more relevant and useful in the future.



Signing Off,

Yash




26 views0 comments

Recent Posts

See All

Comments


bottom of page