Convex Hulls In Tableau

This post includes a run-through of how to create a convex hull soccer chart in Tableau from some of the free data StatsBomb provide.

Hi All,

I recognise it’s been a good few weeks since my last post. Truth be told, juggling isn’t always my forte. This season has excitingly been sprinkled with talks, Iron Viz, and conference but I’m glad to have carved out the time to share another tutorial.

I have grandiose plans of trying to convert as many data analysts python curated charts to Tableau, where they belong! As part of that, it does entail me fighting with python code a fair bit, often thinking what on earth is going on.

This blog will be no different, It has a brief data prep element using the free data from StatsBomb and then we look to create the convex hull chart in Tableau. If you’d like to skip ahead and just do the build, the dataset can be found here.

What is a convex hull chart / Territory Map?

There are a whole range of reasons why convex hull charts can be useful in football. They can be used to explore teams coverage area, spread on the pitch while attacking and defending, as well as shot on goal situations.

In the example below we look at just one individuals placement on the pitch when making passes.

Python Code

I’d like to say a huge thank you to Chun hang who helped me with my code. We went back and forth over email has to how to prep the dataset ready for Tableau. I’m glad together we also figured out how to create the PathID for joining what will be our eventual polygon shape. Please follow him on Twitter here, and his blog here.

If you’d like to access the code it can be found here.

What the code does:

  • We look at the statsbomb free data to identify the list of competitions available, we find the Final of the Womens World Cup for 2020/21.
  • We only look to take the event data for when someone made a pass, and we split the data into X and Y locations.
  • We pick to look at the US team and then find which players had made passes and take Crystal Dunn as our example to plot.
  • We make sure we only include choices of players that have made at least 3 passes to be able to plot our polygon shape.
  • We set up the pitch like normal with python code the output looks like this thanks to Chun Hangs help.

Next

  • We look to find all the passes for Crystal.
  • We take the hull points and anticlockwise add into the dataframe a pathID. This is really important as it will be what we utilise on our path in Tableau, without it, we do not know what order to join the points. Fortunately, the package orders the points in anticlockwise order.
  • We then merge the hull points data back into all of Crystals passes.
  • We export the dataset to CSV ready to use.

Now we have our dataset prepped we can open up Tableau!

Tableau

  • Connect to the data.
  • Drag X onto Columns and Y onto Rows. Make them both dimensions.

Lets create the convex hull first.

  • Change the marks to a polygon
  • Path ID onto path
  • Hull Point onto Colour
  • You will see that when the PathID is yes, it creates the Hull shape we want.
  • We also will want to HIDE (not filter) the PathID that is no – right click the colour legend on the ‘no’ hull points and hide them. Reason for hiding is because we want these points still in our underlying data.

Now your view should look like this:

Next up lets look to add all the pass position points.

  • Add another X to columns as a Dimension.
  • Change the marks to Circle.
  • Remove Hull Point from colour for this card.

Finally we can dual axis these and syncronise.

The last thing to do is to fix our axis and add our football pitch in as a background.

James Smith kindly shows us how this is done in his blog here.

Once you’ve completed this step, the end output should look a little like this.

My only final tip would be to turn the zoom on your pitch off to make sure it keeps its axis in proportion. You can do that by clicking on your pitch sheet, going to map options and unticking the boxes.

As seen below.

And that’s it. Our first Convex Hull chart in Tableau.

The example dashboard can be found here.

Extra Resources:

Football Image background – James Smith

Convex Hulls – Mckay Johns

Convex Hull documentation

MPLSoccer documentation

Looking forward to seeing what you come up with.

LOGGING OFF,

CJ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Website Built with WordPress.com.

Up ↑