Loading the data
The 29th of September saw the release of the yearly EA Sports FIFA title. This time titled FC24. The game often contains a large amount of player stats, this year is no different. The dataset used for this post is concerned with male player stats and was retrieved from Kaggle. The dataset contains a lot of information not all relevant for what we want to do. Some munging was done prior to this post to have a smaller more refined dataset. In general, the dataset was filtered to include only premiere league clubs, exclude goalkeepers (due to large number of NAs for desired columns) and a few key columns were selected. We load relevant packages and take a quick look at the dataset:
Show the code
pacman::p_load(tidyverse,reactablefmtr)
fc24 <- readr::read_csv(file = 'fc24.csv')%>%
select(-...1)
fc24 %>%
head(5)# A tibble: 5 × 11
club_name long_name player_positions pace shooting passing dribbling
<chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 Brighton & Hove A… James Ph… CM, RB 53 70 79 76
2 Everton Ashley Y… LB, RB, LM 65 66 77 75
3 Chelsea Thiago E… CB 51 54 74 72
4 Manchester United Jonathan… CB 37 32 60 58
5 Burnley Jack Cork CDM, CM 40 60 69 68
# ℹ 4 more variables: defending <dbl>, physic <dbl>, overall <dbl>,
# value_eur <dbl>
We have a few categorical columns and a range of numerical columns. The categorical columns denote the club name, player name and positions. The numerical columns denote key player attributes, from pace to overall rating, notably we also have the valuation of the player in euros.
For the visualisation with this dataset we will up the ante by incorporating the techniques used in this post and other features of the fmtr package.
Data Visualisation
There are some notable things we do for the output.Grouping the stat columns from pace to physical. We merge the name and position columns such that the position is shown under the player name. We also apply a consistent visualisation scheme for all attributes and use icons from Font Awesome for the overall column. Finally, data bars are used for the valuation column. It all comes together in the code below:
Show the code
reactable(fc24,
theme = fivethirtyeight(centered = TRUE, header_font_size = 9),
compact = TRUE,
defaultSorted = "value_eur",
defaultSortOrder = "desc",
width = 900,
filterable = TRUE,
searchable = TRUE,
columnGroups = list(
colGroup(name = "Key Stats",
columns = c("pace","shooting","passing","dribbling","defending","physic"))
),
# add border between groups when sorting by the club_name column
rowStyle = group_border_sort("club_name"),
defaultPageSize = 10, # This controls how many rows are shown per page
columns = list(
club_name = colDef(
maxWidth = 80,
name = "Club Name",
rowHeader = TRUE,
# hide rows containing duplicate values on sort
style = group_merge_sort("club_name")
),
long_name = colDef(
name = "Name",
maxWidth = 100,
# merge the "Name" column with the "Postion" column and place it below
cell = merge_column(fc24, "player_positions", merged_position = "below"),
# add a solid border to the right-hand side of the column
style = list(borderRight = "1px solid #777")
),
player_positions = colDef(show = FALSE),
pace = colDef(
name = "Pace",
maxWidth = 65,
cell=color_tiles(fc24,bias=1.3,box_shadow = TRUE),
),
shooting = colDef(
maxWidth = 65,
cell=color_tiles(fc24,bias=0.6,box_shadow = TRUE),
sortNALast = TRUE
),
passing = colDef(
maxWidth = 65,
cell=color_tiles(fc24,bias=0.6,box_shadow = TRUE),
sortNALast = TRUE
),
dribbling = colDef(
maxWidth = 65,
cell=color_tiles(fc24,bias=0.6,box_shadow = TRUE),
sortNALast = TRUE
),
defending = colDef(
maxWidth = 67,
cell=color_tiles(fc24,bias=0.6,box_shadow = TRUE),
sortNALast = TRUE
),
physic = colDef(
maxWidth = 65,
cell=color_tiles(fc24,bias=0.6,box_shadow = TRUE),
sortNALast = TRUE,
style = list(borderRight = "1px dashed rgba(0, 0, 0, 0.3)")
),
overall = colDef(
maxWidth = 68,
cell = icon_sets(data = fc24, colors = viridis::viridis(5),icon_position = "right",icons = "ranking-star")
# style = color_scales(fc24,colors = viridis::viridis(5))
),
value_eur = colDef(
name = "Value (€)",
# style = color_scales(fc24,colors = viridis::viridis(5)),
maxWidth = 100,
cell = data_bars(fc24,
round_edges = TRUE,
border_style = "solid",
border_color = "gold",
border_width = ".8px",
text_position = "above",
number_fmt = scales::dollar_format(prefix = "€")),
style = list(borderLeft = "1px dashed rgba(0, 0, 0, 0.3)")
)
)
) %>%
add_title("EA Sports FC24 Premiere League Player Rankings",font_size = 20) %>%
add_subtitle("What is the overall rating of your favourite player & their value?", font_size = 12) %>%
add_source("Table created by: Nils Indreiten with {reactablefmtr} • Data: kaggle.com • 23-09-20233 update", font_size = 12)What interesting stats can you find about Premiere League players? How much is your favourite player worth?