Throughout this presentation, I’ll figure out if there’s a relation between players’ average prices and results in the German Soccer League – known as Bundesliga. In the dataset, called “bundesliga_players”, there are 14 variables that contain different information about players. The first one is just a number assigned to each club player (there are 515 players in the original data set, but this number will not make sense from the moment that I start cleaning and removing some rows). Then, we have the column “name”, which has the name of the player (first and last name), then there is the “full_name” column (full name of the player as well as how it’s written in their original language). After that, we have “age”, “height”, “nationality” and “place of birth” columns (these columns are all self-explanatory terms). Then we have the “price” and “max_price” columns, their current market value and the maximum price they ever got in millions of euros. We have then the “position” column, which reveals the position of the players on the field. The next column is “shirt_nr,” which is the number of their shirt, then the “club” column, which is the club they play for and the “contract_expires” column, which is the date their contract expires. The last three columns are the “joined club” column (date of when they signed their contract) the “player_agent” (that says the person/company that represents the player) and the “outfitter” column (brand of the cleats that sponsors the players. I’ll explore the relation between the “clubs” and mean “price” of the players of each club, using the “group_by” function and then comparing it with real-life results. The data set source is the “German Bundesliga Soccer League.”
Load tidyverse
We should always load tidyverse, that has all packages we need.
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.2 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.3 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ 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
Load your data set
After downloading from the internet, load your data set according to the directory you have it, in this case, my data set is in the “Documents” folder.
New names:
Rows: 515 Columns: 17
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(9): name, full_name, nationality, place_of_birth, position, foot, club... dbl
(6): ...1, age, height, price, max_price, shirt_nr date (2): contract_expires,
joined_club
ℹ 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.
• `` -> `...1`
Remove academy players and 2nd team players
I’m removing all the academy and 2nd team players because they’re not actually part of the senior team and they may distort the visualization that I want to get (average player’s price by team), since their price is naturally much lower than 1st team players.
Getting the mean price of players grouped by clubs
Now, group the players by club, using the “group_by” function and then use the “summarize” function to obtain the average price of players from each club. It’s important to notice that I removed all the missing values of the price column using “na.rm = TRUE”.
Here I created a graph with the average price of players from all Bundesliga’s clubs. I used the “theme(axis.text.x = element_text(angle = 90))” to fit the names in a way that everyone can read. I’m using a bar chart graph because I’m dealing with one categorical and one quantitative variable.
ggplot(average_price_by_club, aes(x = club, y = Average_Price)) +geom_bar(stat ="identity") +xlab("Clubs") +ylab("Avg Player Price\nin Millions of Euros") +theme(axis.text.x =element_text(angle =90))
Now, let’s see the 4 clubs with the highest average player values!
Now, I decided only to explore the 4 clubs with the highest average player values. I limited to only 4 clubs my new function and used the “wt” function to specify the variable by which I want to select the top N rows in the “Average_price” columns.
Finally, I created my final graph and added some labels to the x and y axes, so as a title and a source. I also flipped the variables using the “coord_flip()” function and added colors of the respective clubs that I’m representing in the graph. I changed the ggplot theme by adding the “theme_linedraw” function.
ggplot(top_4_clubs, aes(x =reorder(club, Average_Price), y = Average_Price, fill = club)) +geom_bar(stat ="identity") +xlab("Clubs") +ylab("Avg Player Price\nin Millions of Euros") +coord_flip() +labs(caption ="German Bundesliga Football League", title ="Top 4 Bundesliga Clubs With\nHighest Average Players Prices") +scale_fill_manual(values =c("Bayern Munich"="red", "RB Leipzig"="blue", "Bor. Dortmund"="yellow", "B. Leverkusen"="black")) +theme_linedraw()
What does this mean?
Bayern is the biggest club in Germany and one of the biggest in the world. Analyzing the graph, we can see that they have the most expensive players (and therefore the “best” ones). You might ask me then, who won the championship? Who was the runner-up? Does this data mean clubs with expensive players will succeed more than the others?
And the table of the 2022-2023 German Soccer Champioship was…
Bundesliga table 2022-2023
Bayern won!
Borussia was 2nd and RB Leipzig was 3rd. Leverkusen was 6th. Union Berlin had one of the lowest average player prices and was 4th! That’s the beauty of soccer! Teams not considered competitive can play well and get amazing results, as Union Berlin did! If you notice, even with a big gap between Bayern and Borussia in terms of players’ price, the only reason Bayern won was that Bayern scored a goal in the last minute against “Koln”, otherwise, Borussia would have won it.
8.
a) Thus, I showed a relation between player’s prices and results. As I mentioned, Bayern is Germany’s biggest and richest club, so they can buy the best (and most expensive) players. That’s the reason why they won the last 11 national championships. In the original data set, several “NA” values existed in the full_name, outfitter and other columns. Still, since I was interested in exploring only club and price values, I only excluded “NA” values of the “price” columns (no values is missing in the “club” column). I did that within the “summarize(Average_Price = mean(price, na.rm = TRUE))”. The command “TRUE” allows me to remove the NAs from the calculation and only consider non-missing values in the summary statistic calculation.
b)Through visualization and real-life results, 3 of the 4 teams with the highest average player values ended up in one of the top four places. The visualization suggests that investment and team performance can have a strong relationship.
c) I would like to see the relation between the average price per position. In soccer, the easiest way to become rich is by scoring goals, so I’m assuming that the average price of players playing in offensive positions is higher than the others. I’ll try to figure this out.