How to create your own heat maps for NWSL advanced stats

Earlier last week, I published a post exploring heat maps for the Portland Thorns’ April 2016 matches, with a focus on Tobin Heath’s performance. Those heat maps are in an Excel spreadsheet, which you can download here.

In this post, I’ll summarize how they work, and how you can create your own for the matches for which we currently have location data. You’ll need a basic understanding of how to use R and how to modify Excel spreadsheets.

How to create your own heat maps

You will only be able to create heat maps for the matches in the WoSo Stats database for which we have location data. You see which ones they are by going to the database.csv file in the WoSo Stats GitHub repository and seeing which matches have a “yes” in the “” column, which will mean they have complete location data for virtually every action that was logged.

If you’d like to help us get more location data logged for more of these matches and you’ve got a couple of hours to spare, you can help!

Getting the data

Anyways, first things first, open up R or R Studio or whatever you use to work in R, and run this code to source the “getting-data.R” and “create-location-stats-table.R” code. The first file will create a data frame in your working directory for the aforementioned database.csv file and a getMatchCsvFiles() function. The second file will create various functions, but the two we’ll be working with will be createMultiLocStatsTabs() and writeFiles().


Now it’s time to pick the matches you want with the getMatchCsvFiles function. This function has the following arguments:
1. competition.string: The name of the competition you want to analyze as it is written in the database’s “competition.string” column. This MUST match exactly what is written in the column, and this argument MUST be written. For the NWSL 2016, you’d write in competition.string = “nwsl-2016”. If you’d like to pick from every single match in the database, then just write in competition.string = “database”
2. The data range you’d like to pick, written as one of several possible arguments. You can pick a specific “round” (such as a week in NWSL play), a set of various “rounds” (such as multiple weeks in NWSL play), or a specific month. These arguments are the following:

  • round: The “round” of the competition, written as round = “nameOfRound” For the NWSL 2016 season, “rounds” are weeks of the season; week 1, for example, would be written as round = “week-1”.
  • multi_round: A vector of different “rounds” of a competition (for the NWSL this would be weeks), written as multi_round = c(“X”, “Y”, “Z”). If you wanted weeks 1 through 3, and week 4, you’d write this as multi_round = c(“week-1”, “week-2”, “week-3”, “week-4”).
  • month_year: The month and year of the matches you’d like, written as MM_YY. For example, matches from May 2016 would be written as month_year = “05_2016”.
  • For now, you can only pick one of these at a time. For example, you can only pick April 2016 matches or Week 1 through Week 3 matches, not all matches from Week 1 through Week 3 that happened in April 2016.
  • You can also just leave this argument blank, in which case you’ll pull everything in the database, according to any further filters you set based on the next few arguments.
  1. team: This is optional. This is the abbreviation for the team whose matches are the only ones you want, written as team = “TeamAbbreviation”. The abbreviation is based on our list of abbreviations for club teams and based on FIFA’s country codes. Double-check the database to make sure the team you want is actually in our database – beyond the NWSL 2016 teams, we only have a bunch of international teams and one random PSG-Lyon match (as of this writing).
  2. location_complete: This is also optional, and is set to default as location_complete = FALSE. What that means is that, by default, you will get all matches, regardless of they have completed location data. For the purposes of this blog post, we will want to set this as location_complete = TRUE

Feel free to play around with this (and let me know if you run into any bugs), but here are some examples of how this function works:

To get all Sky Blue 2016 matches for which we have any data:

getMatchCsvFiles("nwsl-2016", team = "SBFC")

To get all Washington Spirit 2016 matches from the month of June, for which we have complete location data:

getMatchCsvFiles("nwsl-2016", month_year = "06_2016", team = "WAS", location_complete = TRUE)

To get all USWNT matches from 2016 SheBelieves cup, for which we have complete location data:

getMatchCsvFiles("shebelieves-cup-2016", team = "USA", location_complete = TRUE)

For this blog post, we’re going to focus on the code I ran to get all Portland Thorns matches from the first 3 weeks of the season. We already know we have location data for these matches, so specifying location_complete isn’t necessary; however, let’s specify it anyways just in case you weren’t sure.

getMatchCsvFiles("nwsl-2016", multi_round = c("week-1", "week-2", "week-3"), team = "PTFC", location_complete = TRUE)

You should now have a match_list list (a very large one, too) with 3 elements, one for each match spreadsheet, and a match_names vector with 3 elements, one for each matchup name.

Getting the location-based data

The next few steps are pretty simple. Call the createMultiLocStatsTabs() function; set the match_list argument as “match_list” and the match_stat argument as the stat you’re looking for (more on this in the next paragraph); and assign it to variable stats_list. This will create for each match a table with each player in one row and their location-based stats in the columns.

When calling this function, one of the arguments is the match_stat, which is the type of location-based stat you want. As of this writing, you can only get 11 different location-based stats, listed below with the string you need to write in as the argument shown in parentheses. If you wanted to get the largest table possible with columns for each stat (this creates a table with 181 columns), just write match_stat = everything

Or, assign one of these to the match_stat argument:
1. Attempted pases (attempted-passes)
2. Completed passes (completed-passes)
3. Passing completion percentage (pass-comp-pct)
4. Take ons won (take-ons-won)
5. Take ons lost (take-ons-lost)
6. Aerial duels won (aerial_duels-won)
7. Aerial duels lost (aerial-duels-lost)
8. Tackles (tackles)
9. Dispossessions of Opp (opp-dispossess)
10. Opp Poss Disrupted (opp-poss-disrupted)
11. Pressure/Challenges (pressure)
12. Recoveries (recoveries)
13. Interceptions (interceptions)
14. Blocks (blocks)
15. Clearances (clearances)
16. Opp Ball Disrupted (opp-ball-disrupted)

For the set of Portland Thorns matches we are working with, this is the code we would run:

createMultiLocStatsTabs(match_list, match_stat = "everything")

Once you run this, you’ll have a list assigned to the variable stats_list that will have a stats table for each of the three Portland Thorns matches.

Then, write these stats tables as .csv files in your working directory, by running the following. Each stats table’s file name will be determined by the match_stat, which you have to specify again (the data won’t be affected, so you could really name this whatever you want) and by the string values in the match_names vector that was created when we ran the getMatchCsvFiles() function .

writeFiles(stats_list, match_names = match_names, match_stat = "everything")

Run this and, staying with our Portland Thorns April 2016 example, your working directory will now have three .csv files.

To review, here is all of the code that was run since the beginning of this blog post to create the three .csv files that are now in your working directory (the code can also be found here:

getMatchCsvFiles("nwsl-2016", multi_round = c("week-1", "week-2", "week-3"), team = "PTFC", location_complete = TRUE)
createMultiLocStatsTabs(match_list, match_stat = "everything")
writeFiles(stats_list, match_names = match_names, match_stat = "everything")

Create the heat maps

Now the tricky part: creating the heat maps with the data in the .csv files. First, download the Excel template for the heat maps (click on “View Raw” to download), which is just the Portland Thorns April 2016 heat maps, and open it.

Let’s pretend we had this Excel spreadsheet but without the data that’s shown to the right of the heat map, starting with the PTFC-ORL match. Highlight everything in columns “AC” through “HA” from row 1 down to row 29 (as shown in the images below) and clear the contents (DO NOT delete the columns, though).

The heat map will be blank, regardless of what you write into the “Enter name here:” and “Enter stat here:” cells, and the stat info to the right of the heat map and below the cells where you enter the Player and Stat you want will either be zeroes of NAs. This means that the formulas in all those different cells, including the ones that make up the heat map, are looking for data in those columns that we just cleared, but it’s calculating nothing but blanks and errors as there’s nothing there anymore, for now.

Let’s say we didn’t want to re-create the PTFC-ORL match, but instead wanted to use that space we cleared for a BOS-PTFC heat map. Open the “BOS-PTFC-everything.csv” file that you created in your working directory (the following will only work with the “everything” versions of the stats tables) and highlight only the cells that aren’t blank (for this match it’s 27 player rows plus the header row for a total of 29 rows, times the 181 columns, for a total of 5,068 cells you have to highlight). This will look like this in Excel.

Copy those highlighted cells and paste them into the cell at row 1 and column AC, which will fill in the space that was previously taken up by the PTFC-ORL stats. But wait, you’re not done yet! One thing is left to correct, and that’s the team totals.

See that “PTFC” and “ORL” row of numbers in the lower right below the player stats? Those are the total for those stats for each column, which are referred to when creating heat maps for an overall team view. I like to keep the home team on top, so in this example, change “PTFC” in cell AC31 to “BOS” and change “ORL” in cell AC32 to “PTFC”. Then, highlight cells ADH31 (where the totals start) through cell HA31 and search and replace “PTFC” with “BOS”; this changes the formulas in each cell so that they’re now looking for stats from the right team. Do the same for the rows below, searching and replacing “ORL” with “PTFC”. The totals should now be correct.

Finally, in cell Y17 under “Name entered is a team?” is a formula that reads what’s being written into the “Enter name here:” cell and determines, based on the team abbreviations you’ve given it in an OR() formula, if it’s a team that’s been input. Right now this formula is still looking “ORL” as one of the two teams. Change the cell contents from =OR(B5=”PTFC”,B5=”ORL”) to =OR(B5=”PTFC”,B5=”BOS”).

And you’re done! The heat map should work now.


  • It’s easiest to create the heat maps with the template I’ve provided if you had created stats tables with match_stat set as “everything.” I added in the option to create smaller stats tables for the future when the “everything” version of a stats table is far, far bigger than 181 columns. For now, though, it makes more sense to work with the “everything” stats tables as 181-column spreadsheets shouldn’t slow down your computer.
  • You can ignore the passing percentage heat maps for the overall team views, as those are the sum of the percentages for each player. I haven’t yet figured out a way to get the average for the percentages that can account for whether a 0.0 passing pct is there because there were no attempts at all.

Next steps

Help us!

Made it this far? Maybe you can help us out a little more. We need help logging this data. This data only happens because of fans like you who have put hours of their free time into logging data onto Excel spreadsheets. But we need more people helping out, as right now we are very low on volunteers and will be lucky to finish the 2016 season by the time the 2017 season even starts! If you’re interested, read more here about how to help and either send a DM on Twitter to @WoSoStats or email me at to get started. All it takes is a couple of hours of your free time, a willingness to learn, and knowing a thing or two about Excel.

Exploring heat maps for Tobin Heath’s NWSL April 2016 Player of the Month performance

Thanks to the hard work of many volunteers and WoSo fans who have contributed their time to the WoSo Stats Project, we have several matches with location data. The way this project tracks matches means that virtually every action (passes, tackles, pressuring an opponent, lost touches, etc.) has its location on the field logged according to this field breakdown.

The possibilities this creates for analyzing play on the field are numerous. However, logging location data on top of logging the match actions themselves is very time-consuming, so every match has its actions logged first and then location data is added after the fact. This means that only a portion of matches in our database have location data logged, but at this point we have enough matches completely logged that we can start to do some interesting things.

In this post I’ll show how you can use Excel spreadsheets to create heat maps for some of the data we’ve logged. This is just the beginning, but some of this is neat enough to show off already. To keep things focused, I also will show heat maps just for Tobin Heath for her April 2016 Portland Thorns matches.

How the heat maps work

The heat maps featured in this post are in an Excel spreadsheet that can be downloaded from the WoSo Stats GitHub repository (click on “View Raw” to download it). A more in-depth post will follow on how these heat maps function and how you can create your own for any match in our database with location data, but for now it’s important to keep in mind what stats these heat maps depict, how the color gradients are scaled, and just in general how to use them without accidentally breaking the whole thing.

In the Excel spreadsheet, all the data that can be represented on the heat map is in the large table to the right. Don’t mess with this! Each column in that large table is for a given stat in a given zone of the field.

The actual stats I’ve chosen for these heat maps are the following, with a description for what each acronym means listed below:

  • opPass.Att = Open play passes (not free kicks, throw-ins, corner kicks, goal kicks) attempted
  • opPass.Comp = Open play passes attempted
  • opPass.Pct = Open play pass completion percentage
  • Int = Interceptions
  • TO.Won = Take ons won
  • TO.Lost = Take ons lost
  • AD.Won = Aerial duels Won
  • AD.Lost = Aerial duels lost
  • Tackles = Tackles that dispossessed an opposing player with the ball
  • Pressure = Instances where a player applied pressure onto an opposing player’s action, without actually attempting a tackle or dispossession
  • Recoveries = Winning possession of a loose ball

More detail on some of the above stats and how they’re logged can be found here.

To actually create a heat map for a specific player from that heat map’s match, type in her name in the cell below “Enter name here.” The heat map will be for the stat in the cell below “Enter stat here:”, which you can also change so long as it matches one of the stats listed below. The stat for that player for each zone will be listed in the grey-shaded cells.

A note on how the color gradient works. For the sake of simplicity, for now, in this Excel spreadsheet the minimum (white) is always 0 and the maximum for each stat (darkest green) is the largest number out of all the zones for all the players. For example, for the Portland Thorns vs. Orlando Pride match above for the opPass.Att stat, Emily Sonnett had the most open play passes attempted from any one zone, with 20 open play passes attempted from the center of the defensive 3rd (DC). So, that’s the maximum for the opPass.Att stat. The same logic holds true for all the other stats.

I’ve got formulas in the Excel spreadsheet to also account for finding the maximum for a team overall, as you can also just type in the team acronym in the cell under the “Enter name here:”

Tobin Heath’s April 2016 NWSL Player of the Month performance

If you’ve already downloaded the Excel spreadsheet, you’ve hopefully noticed you can create heat maps for the three NWSL matches in there for any of the players who played. However, I’m just going to spend the rest of this post looking through the stats for Tobin Heath, as she was voted the Player of the Month by NWSL Media for that month of April. That Tobin Heath is a great player who had a great start to the season, well, that’s not something for which you really need a heat map. But the following will be fun to see how Heath’s passing and take ons were distributed across the field, especially compared to other players.

Tobin Heath in Portland Thorns vs Orlando Pride (Week 1)

The first thing that stood out to me for this match was the distribution of Heath’s passing across a large swath of the field. Her heat map for her open play passing attempts (opPass.Att) is light green, but there’s a lot of light green especially in the opponent’s half.

There weren’t a lot of players who had that much green in the opponent’s half. The only other player who comes close to that many attempted passes was Alex Morgan, shown below.

And Heath’s passing completion percentage was also fairly high in the attacking third compared to other players (here’s the tweet with screenshots of heat maps for Alex Morgan, Kaylyn Kyle, and Mana Shim, who had similarly high pass completion percentages in the attacking 3rd).

Heath’s heat map for her take ons won is noteworthy because, after looking at the heat map for her entire team, it looks like every take on won by Portland in the attacking third (5) belonged to her.

Finally, aside from her passing and playmaking ability, Heath also appears to have applied a good amount of pressure on opponents. Below, her heat map for pressure applied is fairly green up and down her left side of the field.

By comparison, the two players who look like they applied the most pressure in the attacking third were Portland’s Nadia Nadim and Orlando’s Alex Morgan.

Tobin Heath in FC Kansas City vs Portland Thorns (Week 2)

Similar to her previous week, Heath had a very active passive day against FCKC in Week 2 along her left flank, with a high number of passing attempts centered around that attacking left corner.

The only other player with that many passing attempts in the opponent’s left or right corner was her teammate Klingenberg.

Heath’s passing completion percentage was also high across two-thirds of the field, again, especially in the attacking third.

The four other players from this game who appeared to have similarly high passing completion percentage numbers in the attacking third were Erika Tymrak, Allie Long, Mandy Laddish, & Lindsey Horan.

As for take ons won, Heath won a similar amount of take ons in the opponent’s half compared to the previous week.

Take ons lost are worth looking at for Heath here, as it appears she lost a few more take on attempts against FCKC (5) compared to her previous week against ORL (2).

Other players that game with a similar number of take ons won in the attacking third were Meghan Klingenberg, Mandy Laddish, and Allie Long.

As far as recoveries the loose ball goes, Heath did a good amount of it in the attacking third, especially in that dangerous center of the attacking third in front of the 18-yard box.

Two other players whose recoveries in the attacking third looked similar to Heath were Jen Buczkowski and Desiree Scott.

Heath’s pressure applied to opponent’s in their defensive corners also looked impressive, comparable to just a few other players from this game.

Tobin Heath in Boston Breakers vs. Portland Thorns (Week 3)

Finally for this (short) NWSL month, there’s Heath’s performance at Boston where she had another day of passing attempts bunched into the attacking third’s left, similar to the previous week against FCKC.

Kristie Mewis had a heat map similar to this one, with almost as many passing attempts from the attacking third left, and a few more than Heath further down the center of the field.

Heath’s passing completion percentage in the attacking third looks somewhat inverted compared to Mewis. She “only” had a passing percentage of 50% in the attacking third’s left – I put “only” in quotation marks because with more data from more matches it’ll be interesting to see if that low of a passing percentage is actually relatively good compared to what the average player gets. Either way, Mewis had a much better passing percentage, 80%, in that attacking third left.

Compared to the rest of the month, Heath had what looks like significantly less take ons won across the field; 3 compared to 7 against Orlando and 10 against FCKC.

Heath also had the least recoveries of the month against Boston; 6 compared to 10 against Orlando and 14 against FCKC

Final Thoughts & Next Steps

The stats shown here appear to back up the eye test; Heath was a presence, attempting passes across a wide span of the field. She was a threat in the attacking third left, getting off a good number of passes and take ons from that corner.

There’s a lot more that could be done with heat maps, though. I included only a few stats in these heat maps because some stats I didn’t include, such as assists, happen very rarely; I found that these heat maps and the use of a color gradient are most useful and interesting for actions that happen many times such as passes or pressuring an opponent. One idea that I will pursue is creating a heat map that incorporates several matches and, rather than using totals, will use a “per 90 minutes” stat. That is, to use interceptions as an example, instead of showing how many interceptions a player got in one match (which is rarely more than one in any one zone for one match), show how often she gets an interception in that zone per 90 minutes of play.

There’s also the issue of how to account for a scale that is heavily skewed to one extreme, such as the passing completion percentage stat. Most players, even those with an average passing day, will have a passing completion percentage well above 50 percent, so having the minimum below 0 isn’t very useful.

There’s also the matter of how to account for how hard it is to rack up certain stats in some zones compared to others. For example, in the Orlando game, Heath had a fairly evenly distributed number of passes across the field. However, it may not be giving Heath enough credit by having her 5 passing attempts in the defensive middle’s left (DML) be the same shade of green as her 5 passing attempts in the opponent’s 18-yard box. I’m assuming that any one player getting that many passing attempts in the 18-yard box in any one game is rare, so that zone could reasonably be even greener if it were put up against some sort of scale that took into account what the upper and lower quartiles are for that specific zone; I’d bet if we looked at every player from that month and looked the number of passing attempts each one managed to make in the 18-yard box, Heath’s 5 would be somewhere in the top 25%. On the other side of the field, by that standard Heath’s 5 passing attempts in the defensive middle’s left would probably be an even lighter green, since that’s almost always a very active part of the field, especially for left backs, center backs, and defensive midfielders.


A more in-depth post on how this heat maps works is coming, but for now you can browse the Excel spreadsheets with the raw match actions data for each match here:
* PTFC-ORL (Week 1)
* FCKC-PTFC (Week 2)
* BOS-PTFC (Week 3)

The stats tables next to the heat maps, all by themselves in their own csv files, can be found here:
* PTFC-ORL (Week 1) location-based stats
* FCKC-PTFC (Week 2) location-based stats
* BOS-PTFC (Week 3) location-based stats

And, finally, the R code that created the above csv tables can be found here. That source from this R code that has functions for fine-tuning what matches from our database you’re looking for and from this R code that creates the stats tables.

Help us!

You made it this far down the post! Maybe you can help us out a little more. We need help logging this data. This data only happens because of fans like you who have put hours of their free time into logging data onto Excel spreadsheets. But we need more people helping out. If you’re interested, read more here about how to help, and then send me a DM at Twitter at @WoSoStats or email me at to get started. All it takes is a couple of hours of your free time, a willingness to learn, and knowing a thing or two about Excel.