Welcome back to another tutorial. Hope everyone is doing well. This is my first blog back using my new website! Do take a look around, get familiar and see what you make of it. I really wanted to bring my personal brand more to life whilst staying true to the content and style of work I put out.
With my new site…. all repo specific links for data and dashboard templates will be found at the top of the page. This was part of a huge migration piece to make life easier to manage and organise.
The tutorial today looks to create Soccer Hex Maps in Tableau. With the World Cup being on, I started to revisit some of my old blogs from the years and one I quite enjoyed initially creating was the tutorial on retrieving Understat data. You can find the original blog here.
A copy of the dataset that the code produces is stored within the Git Repository at the top of the page.
We will solely be looking at producing the visual element today.
Firstly connect to the player shot data.
First thing I do is scale the map values up – It makes it easier to work with.
See below for a visual representation of this.
Next we will want to create our hex bins from the data.
Create a parameter called adjuster. Within my workbook this is set to a float of 0.3 but this adjuster value will be dependent on the scale that you want your hex map sizes. The higher this value, the smaller the hex’s (more hex’s on the pitch).
Of course, therefore the lower the value, the less hex’s presented on the pitch.
HEXBINX([X New]*[adjuster],[Y New]*[adjuster])/[adjuster]
HEXBINY([X New]*[adjuster],[Y New]*[adjuster])/[adjuster]
Plot Hex Y onto columns, and Hex X onto rows making sure they are both dimensions. (not averages)
This is all the different bins of all the different shots. But we really want it to make sense by adding a football pitch behind it.
Take the pitch image from the repo and align it with the following co-ordinates.
Make the X field based on our Hex X field. with Left padding -7, Right padding 127.
Make the Y field based on our Hex Y field. With bottom padding -7, top padding 87.
In the options, make sure not to click ‘always show image’ if you want to only make the pitch a half pitch.
Next fix the axis. I tend to fix Hex X to 60-125 & Hex Y -7 to 87 – similar to what we see in the mapping co-ordinates, but now just showing half the pitch.
Add the hexagon shape from Github into your tableau public repository, changing your marks card to shape.
Lastly, we can adjust the size slider bar to match the sizing of our pitch. It is best to go back and do this once you have added it to your dashboard.
We also can change our adjuster parameter to see how many hex’s we want on our page.
The final thing is to add our colour metric, for now I will plot the count of number of shots as a measure onto the colours mark.
By reducing the opacity a little we can still see the pitch outline.
There we have it our hex shot map showcasing where the most shots are taken from last season. We could take this further by picking specific players, you’ll notice in my final design I have added a filter just to look at the top 5 strikers that season, adding the player to the columns mark.
Taking it further:
- Try plot a small multiples of each the Top 20 Strikers this season.
- Try Overlaying individual shots over the top of the hex map.
- Try adding where the results = goals instead of total shots into the colour marks.
Let me know how you get on with this one.