The dataset I used covers data for the NWSL 2023 season, focusing on player performance statistics for all teams in the league, including goals, assists, chances created, fouls committed, and more. As a DC sports fan, I decided to focus only on the 24 woman roster of the professional soccer team Washington Spirit.
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.0 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
New names:
Rows: 347 Columns: 42
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(4): team, player_name, conc_player_name, position dbl (38): games_played,
games_started, minutes_played, goals, accurate_pass_...
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `accurate_pass_percentage` -> `accurate_pass_percentage...9`
• `accurate_pass_percentage` -> `accurate_pass_percentage...31`
Warning: Setting row names on a tibble is deprecated.
nwsl <- nwsl[,5:10]nwsl2_matrix <-data.matrix(nwsl2)nwsl2_heatmap <-heatmap(nwsl2_matrix, Rowv=NA, Colv=NA, col =topo.colors(25), scale="column", margins=c(5,10),xlab ="Player Stats",ylab ="Player Name",main ="Washington Spirit Player Stats for 2023 season")
Final Thoughts
In my data cleaning process, the dataset did not contain any NA values. Instead, the source used 0’s to represent anything not aplicable. My cleaning focused entirely on the columns. I used the tolower() and gsub() functions to ensure all column names were in lowercase letters and spaces were replaced with underscores.The visual represents player statistics across 21 columns. It was no surprise that Trinity Rodman had impressive offensive statistics, given her high participation in the attacking third. However, I was surprised to see that Paige Metayer had a high dribbling rate and many completed passes but did not record any assists over the season.As I am relatively new to creating heatmaps, there were several elements I wanted to include but struggled with. Firstly, I was unable to select specific columns for the x-axis eventhough I was using the [#,#] function. Additionally, I wanted to make the x and y-axis text smaller and angled for better readability but struggled to do so. I also wanted to add a legend to my heatmap. However, I found that features like angling text and adding legends work differently unless using the ggplot package. I definitely want to make edits to my heatmap in the near future when I expand my knowledge.