Markdown
title: “Final Project - IPL Player Analysis” author: “Himani Kanwal” output: html_document —
```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(tidyverse) library(ggplot2) library(plotly) library(gganimate) Import Data {r data_import} players <- read_csv(“ipl2026_players.csv”) players <- as_tibble(players) Figure 1: Top 20 Highest-Paid Players fig1_data <- players %>% arrange(desc(AuctionPrice)) %>% slice(1:20)
ggplot(fig1_data, aes(x=reorder(PlayerName, AuctionPrice), y=AuctionPrice, fill=Team)) + geom_bar(stat=“identity”) + coord_flip() + labs(title=“Top 20 Highest-Paid Players (IPL 2026)”, x=“Player”, y=“Auction Price (₹ Crore)”, fill=“Team”) Figure 2: Team Salary Composition by Role fig2_data <- players %>% group_by(Team, Role) %>% summarise(TotalSalary=sum(AuctionPrice, na.rm=TRUE))
ggplot(fig2_data, aes(x=Team, y=TotalSalary, fill=Role)) + geom_bar(stat=“identity”) + labs(title=“Team Salary Composition by Role”, x=“Team”, y=“Total Salary (₹ Crore)”, fill=“Role”) Figure 3: Auction Price vs Runs Scored (Interactive Scatter) fig3_data <- players %>% filter(Role %in% c(“Batsman”,“All-Rounder”))
p <- ggplot(fig3_data, aes(x=AuctionPrice, y=RunsScored, color=Team, size=StrikeRate, text=paste(“Player:”, PlayerName))) + geom_point() + labs(title=“Auction Price vs Runs Scored”, x=“Auction Price (₹ Crore)”, y=“Runs Scored”, color=“Team”, size=“Strike Rate”)
ggplotly(p) Figure 4: Overseas vs Domestic Player Salaries (Dumbbell Chart) fig4_data <- players %>% group_by(Team, Nationality) %>% summarise(AverageSalary = mean(AuctionPrice, na.rm = TRUE)) %>% pivot_wider(names_from = Nationality, values_from = AverageSalary)
ggplot(fig4_data, aes(y = Team)) + geom_point(aes(x = India), color = “blue”, size = 3) + geom_point(aes(x = Overseas), color = “red”, size = 3) + geom_line(aes(x = India, xend = Overseas, y = Team, yend = Team), color = “gray”) + labs(title = “Overseas vs Domestic Player Salaries by Team”, x = “Average Salary (₹ Crore)”, y = “Team”) Figure 5: Distribution of Batting Strike Rates by Role ggplot(players %>% filter(!is.na(StrikeRate)), aes(x=StrikeRate, fill=Role)) + geom_density(alpha=0.4) + labs(title=“Distribution of Batting Strike Rates by Role”, x=“Strike Rate”, y=“Density”, fill=“Role”) Figure 6: Top Wicket-Takers fig6_data <- players %>% arrange(desc(WicketsTaken)) %>% slice(1:20)
ggplot(fig6_data, aes(x=reorder(PlayerName, WicketsTaken), y=WicketsTaken, fill=Team)) + geom_col() + coord_flip() + labs(title=“Top 20 Wicket-Takers (IPL 2026)”, x=“Player”, y=“Wickets Taken”, fill=“Team”) Figure 7: Team × Player Role Count (Heatmap) fig7_data <- players %>% group_by(Team, Role) %>% summarise(Count=n())
ggplot(fig7_data, aes(x=Team, y=Role, fill=Count)) + geom_tile() + labs(title=“Team × Player Role Count”, x=“Team”, y=“Role”, fill=“Count”) Figure 8: Runs Scored per Match Over the Tournament (Animated Line Chart) # Replace ‘matches’ with your actual match-level dataset fig8_data <- matches %>% group_by(Week, Team) %>% summarise(TotalRuns = sum(Runs, na.rm = TRUE))
p <- ggplot(fig8_data, aes(x = Week, y = TotalRuns, color = Team, group = Team)) + geom_line(size = 1.2) + labs(title = “Runs Scored per Match Over IPL 2026”, x = “Week of Tournament”, y = “Total Runs”, color=“Team”) + theme_minimal()
p + transition_reveal(Week)