How to Make an xG Flow Chart in Tableau
What is an xG Flow Chart?
An xG flow chart is a visualization type used in football/soccer analytics to understand the quantity and quality of shots taken throughout a match. It is a great way to see how a match is played out and to determine whether a team over or underperformed their xG score.
Data Set Up
To get started we need xG goal data from a match. Two ways you can get this data is by scraping it from understat.com or by manually entering the data into a spreadsheet from infogol.com. If you’re recording shots on your own, you can also use Ben Torvaney’s(@Torvaney) xG interactive tool to get an xG score. You can find this on Ben’s github here. The 2 main things you’ll need in your data is the minute and xG score. Shot outcome isn’t absolutely necessary in your data, but it can come in handy if you want to annotate your visualization. To get the lines for both teams to plateau at the end of the line make sure to add this (refer to Figure 1). Customize the ending plateau to whatever the last minute of the game is. If 1 team registers multiple shots in the same minute, make sure to differentiate them in your data. For example, if 2 shots took place in the 20th min, record the first shot as 20 and the second shot as 20.5. If shots are recorded with identical minute values then the xG will be aggregated and in the chart it’ll look like one shot. We want to be able to differentiate each shot so the plot can tell a better story of the match. Feel free to use my data if you want to follow along. You can access it here.
Getting Started in Tableau
Once you have your data loaded into Tableau, drag Minute into columns and xG into rows and it should look something like this (Figure 2). Make sure the Minute field is a Measure, the cell should look green instead of blue. Below is what the plot should look like so far. Still some ways to go, but now we have to make some changes with the Minute and xGoal measure.
Adjusting the Measures
For the measures, right click on “cell” and we want the xG and Minute measure to look like this (Figure 3). This flowchart takes the running total of xG, so make sure that “Running Total” is checked off. You’ll know that the xG is using the running total calculation when a small delta symbol (Δ) appears next to the cell. Your visualization should now look like the image below. Once you complete this step, let’s take a look at the Marks section.
Adjusting the Marks Section
To get two separate lines for each team, drag the “Team” cell into “Color”. Feel free to add any other relevant info from your data by dragging those cells under “Tooltip”. You can see the info when hovering your mouse over the line. I’ll be dragging xG under tooltip to see how much xG was added to the running total from each shot. To create the staircase appearance for your line, click on Path and select the middle option (Figure 4). Now our visualization should look like the image below. Now it’s time to add some final touches!
Final Touches
First, drag your sheet into a dashboard and play with the background and line color however you please. Start by adjusting the axis range and make both the X and Y axis start at 0. You can do this by right clicking on the axis, clicking on Edit Axis, and then adjust the Fixed Start to equal 0. Another thing I prefer doing is annotating the point(s) of the lines where a goal was scored. All you have to do is right click on the desired point -> hover over annotate -> click on point. A text box should appear and you’ll be able to customize it however you please. I also imported small soccer ball logo images and placed them at each point where a goal was scored. I included the ball logo next to the Team legend as well. To add a line on the Minute axis to show when half time is, go into the sheet where the graph is and in the Analytics tab in the top left corner, drag “Average Line” under Table and Minute (Figure 5). The final thing I did was sum up the xG and goal total in separate sheets for both teams and placed them at the end of the lines. My final product looks like this!
That is how you create an xG Flow Chart in Tableau. It is super quick and simple, hope you all enjoyed it. Hit me up @FcAyushNarayan if you have any questions. If you follow this tutorial, I’d love to see what your work looks like. Please make sure to share this tutorial, I’d really appreciate it!
Follow me @ FcAyushNarayan on Twitter