In the realm of football rivalries, few contests capture the imagination quite like El Clásico, the clash between Barcelona and Real Madrid. For decades, these titans of Spanish football have engaged in fierce battles, each match a spectacle of skill, passion, and rivalry. However, behind the drama of individual games lies a broader narrative, one that unfolds over seasons and years. In this project, we delve into the statistical landscape of La Liga from 2014 to 2020, focusing particularly on Barcelona’s performance and their encounters with Real Madrid. Through a comprehensive analysis of key metrics, I was aiming to uncover trends that illuminate Barcelona’s decline in dominance over both La Liga as a whole and their arch-rivals, Real Madrid. As a soccer player myself, I very much enjoyed working on this.
The dataset I am working with covers the span of La Liga from 2014 to 2020, offering a rich assortment of statistics that delve into the heart of each match played. It’s a treasure trove of information, providing insights into the performance not only of Barcelona but also of their long-standing rival, Real Madrid. From goals scored to possession percentages, from disciplinary actions to shot accuracy, the dataset paints a vivid picture of the highs and lows experienced by these iconic teams over the years. As we sift through the data, we’re poised to uncover the intricate stories and trends that have shaped the landscape of Spanish football during this time period. I’ve taken a few interesting and valuable metrics provided in the dataset, and I tried to visualize success/decline in success and it’s factors for one of the greatest soccer teams ever - FC Barcelona
First visualization examines Barcelona’s total goals scored in La Liga across the years 2014-2020. The data reveals a concerning trend: a steady decline in Barcelona’s goal-scoring prowess over this period. This decline suggests a potential erosion of the attacking potency that has long been synonymous with the Catalan club.
library(dplyr)
library(ggplot2)
library(ggthemes)
library(ggrepel)
library(scales)
library(gsubfn)
library(proto)
library(RSQLite)
library(sqldf)
library(reshape2)
library(RColorBrewer)
library(tidyr)
library(gridExtra)
df <- read.csv("C:/Users/Korisnik/Desktop/combined_data_laliga.csv")
# Total Goals over years
tot_goals <- sqldf("SELECT SUM(`Home.Team.Goals.Scored`) AS 'Home Goals', SUM(`Away.Team.Goals.Scored`) AS 'Away Goals', year FROM df GROUP BY year")
# Melt the data frame to long format
tot_goals_long <- melt(tot_goals, id.vars = "year")
# Convert year to factor with levels from 2014 to 2020
tot_goals_long$year <- factor(tot_goals_long$year, levels = 2014:2020)
# Create the bar plot with custom colors
ggplot(tot_goals_long, aes(x = year, y = value, fill = variable)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Total Home and Away Goals Over Years",
x = "Year",
y = "Total Goals",
fill = "Goals Type") +
scale_fill_manual(values = c("Home Goals" = "#1D8348", "Away Goals" = "#F47B20")) + # Set custom colors
theme_minimal()
Next, while browsing the La Liga dataset, I’ve come accross a metric called “Match Excitement” and I explored the relationship between match excitement levels and the issuance of yellow and red cards. My analysis indicates a notable correlation between the two, suggesting that matches characterized by heightened excitement are often accompanied by an increase in disciplinary actions. This correlation underscores the intensity of encounters such as El Clásico, where emotions run high and the stakes are immense.
#El Clásico Hype chart
el_classico_hype <- sqldf("SELECT `Home.Team.Yellow.Cards` AS yel_h, `Home.Team.Red.Cards` AS red_h,
`Home.Team.Yellow.Cards` AS yel_a, `Home.Team.Red.Cards` AS red_a, year, `Match.Excitement` AS mat_e
FROM df WHERE (`Home.Team` = 'BARCELONA' AND `Away.Team` = 'REAL MADRID') OR (`Home.Team` = 'REAL MADRID' AND `Away.Team` = 'BARCELONA')")
# Calculate total yellow and red cards for home and away teams
el_classico_hype <- el_classico_hype %>%
mutate(total_yellow_cards = yel_h + yel_a,
total_red_cards = red_h + red_a)
# Calculate average value of `mat_e` for each year
avg_mat_e <- el_classico_hype %>%
group_by(year) %>%
summarize(avg_mat_e = mean(mat_e))
# Calculate total yellow and red cards for each year
total_cards <- el_classico_hype %>%
group_by(year) %>%
summarize(total_yellow_cards = sum(total_yellow_cards) / 2.5, # Dividing by 2
total_red_cards = sum(total_red_cards) / 2.5) # Dividing by 2
# Merge the average excitement and total cards data
combined_data <- merge(avg_mat_e, total_cards, by = "year")
# Convert the data to long format for easier plotting
combined_data_long <- combined_data %>%
pivot_longer(cols = c(avg_mat_e, total_yellow_cards, total_red_cards),
names_to = "variable",
values_to = "value")
# Convert year to factor with levels from 2014 to 2020
combined_data_long$year <- factor(combined_data_long$year, levels = 2014:2020)
# Create line chart with additional bars for yellow and red cards
p <- ggplot(combined_data_long, aes(x = year, color = variable, group = variable)) +
geom_line(data = filter(combined_data_long, variable == "avg_mat_e"), aes(y = value)) +
geom_point(data = filter(combined_data_long, variable == "avg_mat_e"), aes(y = value)) +
geom_bar(data = filter(combined_data_long, variable != "avg_mat_e"),
aes(fill = variable, y = value), stat = "identity", position = "dodge") +
labs(title = "Excitement related to Yellow/Red Cards in El Clásico",
x = "Year",
y = "Average Excitement",
color = "Metrics", fill = "Metrics") +
scale_color_manual(values = c("avg_mat_e" = "black"),
labels = c("avg_mat_e" = "Average Match Excitement")) +
scale_fill_manual(values = c("total_yellow_cards" = "#1D8348", "total_red_cards" = "#F47B20"),
labels = c("total_yellow_cards" = "Total Yellow Cards", "total_red_cards" = "Total Red Cards")) +
theme_minimal()
# Add a second y-axis for total cards divided by 2
p <- p + scale_y_continuous(sec.axis = sec_axis(~ . * 2.5, name = "Total Yellow/Red Cards")) +
theme(axis.title.y.right = element_text(color = "black"),
axis.text.y.right = element_text(color = "black"))
p
In my third visualization, I was looking in on how Barcelona has been playing against their arch-rivals, Real Madrid at Home field. Looking at the number of shots Barcelona takes in these matches over the years, we notice that they’ve been scoring fewer goals. This could mean that Real Madrid has changed their tactics, or it could suggest that Barcelona that Barcelona’s domination over Real Madrid has declined over the years.
classico_shot_bd <- sqldf("SELECT `Score`, year, `Home.Team.On.Target.Shots`, `Home.Team.Off.Target.Shots`,
`Home.Team.Blocked.Shots`, `Home.Team.Goals.Scored` FROM df WHERE (`Home.Team` = 'BARCELONA' AND `Away.team` = 'REAL MADRID')")
# Melt the dataframe
classico_shot_bd_melt <- melt(classico_shot_bd, id.vars = c("Score", "year"),
measure.vars = c("Home.Team.On.Target.Shots",
"Home.Team.Off.Target.Shots",
"Home.Team.Blocked.Shots"),
variable.name = "Shot_Type", value.name = "Shots")
# Define colors
pastel_colors <- c("#1D8348", "#FFD700", "#F47B20")
# Get all unique years present in the dataset
all_years <- unique(classico_shot_bd_melt$year)
# Plotting
ggplot(classico_shot_bd_melt, aes(x = factor(year, levels = all_years), y = Shots, fill = Shot_Type)) +
geom_bar(stat = "identity") +
geom_text(aes(label = Shots), position = position_stack(vjust = 0.5), color = "black", size = 3) +
labs(title = "El Classico Shot Breakdown",
x = "Year",
y = "Number of Shots",
fill = "") + # Removed legend title
scale_fill_manual(values = pastel_colors, name = "Shot Type", labels = c("On Target Shots", "Off Target Shots", "Blocked Shots")) + # Assign pastel colors and customize legend labels
theme_minimal() +
theme(legend.position = "bottom")
Fourth and fifth visualizations scrutinize the significance of ball possession in El Clásico matches, both at home and away. Contrary to conventional wisdom, this analysis reveals that ball possession percentage does not necessarily correlate with match outcomes.
bar_cls_pos_h <- sqldf("SELECT Score, year, `Home.Team.Possession..`, `Away.Team.Possession..` FROM df WHERE (`Home.Team` = 'BARCELONA' AND `Away.Team` = 'REAL MADRID')")
# Function to create pie chart for each game
create_pie_chart <- function(data_row) {
# Create data frame for the pie chart
data <- data.frame(
team = c("Barcelona", "Real Madrid"),
possession = c(data_row$Home.Team.Possession.., data_row$Away.Team.Possession..)
)
# Define custom colors for Barcelona and Real Madrid
barca_color <- "#F47B20" # Barcelona color
madrid_color <- "#0066B2" # Real Madrid color
# Create pie chart for the game
chart <- ggplot(data, aes(x = "", y = possession, fill = team)) +
geom_bar(stat = "identity", width = 1) +
geom_text(aes(label = paste0(possession, "%")),
position = position_stack(vjust = 0.5),
size = 4, color = "white") + # Add percentage labels
coord_polar(theta = "y") + # Adjusting polar coordinates
labs(title = paste("El Clásico -", data_row$year), subtitle = (data_row$Score),
fill = "") +
theme_void() +
scale_fill_manual(values = c("Barcelona" = barca_color, "Real Madrid" = madrid_color), # Custom colors
labels = c("Barcelona", "Real Madrid")) + # Custom legend labels
theme(legend.position = "bottom", # Place legend at the bottom
plot.subtitle = element_text(size = 10, hjust = 0.5)) # Center subtitle
return(chart)
}
# Create a single headline
headline <- ggplot() +
geom_text(aes(x = 0.5, y = 0.5, label = "Barcelona Home Possession over the years"),
size = 6, fontface = "bold", hjust = 0.5, vjust = 0.5) +
theme_void()
# Create pie charts for each game
pie_charts <- lapply(1:nrow(bar_cls_pos_h), function(i) {
chart <- create_pie_chart(bar_cls_pos_h[i,])
})
# Combine the headline and pie charts in a grid layout
grid.arrange(headline, arrangeGrob(grobs = pie_charts, ncol = 3), nrow = 2, heights = c(0.1, 0.9))
Furthermore, by delving into recent encounters between Barcelona and Real Madrid, you can uncover a sobering reality: Barcelona has suffered a string of losses and draws against their arch-rivals, indicating a decline in their historical dominance in the last 20 years in both La Liga and El Clásico.
bar_cls_pos_a <- sqldf("SELECT Score, year, `Home.Team.Possession..`, `Away.Team.Possession..` FROM df WHERE (`Away.Team` = 'BARCELONA' AND `Home.Team` = 'REAL MADRID')")
# Function to create pie chart for each game
create_pie_chart <- function(data_row) {
# Create data frame for the pie chart
data <- data.frame(
team = c("Real Madrid", "Barcelona"),
possession = c(data_row$Away.Team.Possession.., data_row$Home.Team.Possession..)
)
# Define custom colors for Barcelona and Real Madrid
barca_color <- "#F47B20" # Barcelona color
madrid_color <- "#0066B2" # Real Madrid color
# Create pie chart for the game
chart <- ggplot(data, aes(x = "", y = possession, fill = team)) +
geom_bar(stat = "identity", width = 1) +
geom_text(aes(label = paste0(possession, "%")),
position = position_stack(vjust = 0.5),
size = 4, color = "white") + # Add percentage labels
coord_polar(theta = "y") + # Adjusting polar coordinates
labs(title = paste("El Clásico -", data_row$year), subtitle = (data_row$Score),
fill = "Team") +
theme_void() +
scale_fill_manual(values = c("Real Madrid" = barca_color, "Barcelona" = madrid_color), # Custom colors
labels = c("Real Madrid", "Barcelona")) + # Custom legend labels
theme(legend.position = "bottom", # Place legend at the bottom
plot.subtitle = element_text(size = 10, hjust = 0.5)) # Center subtitle
return(chart)
}
# Create pie chart for each game
pie_charts <- lapply(1:nrow(bar_cls_pos_a), function(i) {
chart <- create_pie_chart(bar_cls_pos_a[i,])
})
# Create the headline
headline <- ggplot() +
geom_text(aes(x = 0.5, y = 0.5, label = "Barcelona Away Possession over the years"),
size = 6, fontface = "bold", hjust = 0.5, vjust = 0.5) +
theme_void()
# Combine the headline and pie charts in a grid layout
grid.arrange(headline, arrangeGrob(grobs = pie_charts, ncol = 3), nrow = 2, heights = c(0.1, 0.9))
As I reflect on our journey through La Liga from 2014 to 2020, one undeniable truth emerges: Barcelona’s reign is slipping. Delving into the data and dissecting the drama of El Clásico, I’ve witnessed a narrative of transformation and rivalry unfolding before my eyes.
Barcelona’s decline in goal-scoring prowess over the seasons prompts us to question the club’s offensive strategies and overall evolution. Moreover, the observed correlation between match excitement and disciplinary actions highlights the intensity of clashes like El Clásico, where emotions frequently spill onto the pitch.
The diminishing number of shots on goal against Real Madrid further emphasizes the shifting dynamics of this historic rivalry. Barcelona no longer poses the same offensive threat to their arch-rivals, hinting at potential strategic adjustments or deeper structural changes within the club.
Most notably, the revelation regarding ball possession in El Clásico contests challenges conventional wisdom, showing that possession doesn’t always translate to dominance, as recent matches have demonstrated. Barcelona’s recent struggles against Real Madrid, culminating in losses and draws, serve as a sobering reminder of their declining influence in both La Liga and El Clásico history.
Reflecting on these findings, it becomes apparent that Barcelona’s decline isn’t just a statistical anomaly but reflects broader trends in Spanish football. As the landscape evolves, Barcelona must adapt to meet the challenges ahead. While their days of unquestionable dominance may be fading, the enduring spirit of competition ensures that El Clásico remains a captivating spectacle for football fans worldwide.