library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readxl)
df<-read_excel("C:/Users/my tech/OneDrive/Desktop/python/MCBA_stats.xlsx")
### Summary of the mongolian college basketball association(MCBA) player stats of the 2024-2025 season so far
summary(df)
## â„– Player Teams Game
## Min. : 1.0 Length:219 Length:219 Min. : 5.000
## 1st Qu.: 55.5 Class :character Class :character 1st Qu.: 8.000
## Median :110.0 Mode :character Mode :character Median : 9.000
## Mean :110.0 Mean : 9.132
## 3rd Qu.:164.5 3rd Qu.:11.000
## Max. :219.0 Max. :14.000
## PTS REB AST BLK
## Min. : 0.000 Min. : 0.000 Min. :0.000 Min. :0.0000
## 1st Qu.: 2.300 1st Qu.: 1.700 1st Qu.:0.400 1st Qu.:0.0000
## Median : 4.900 Median : 2.900 Median :0.900 Median :0.1000
## Mean : 6.436 Mean : 3.426 Mean :1.262 Mean :0.2982
## 3rd Qu.: 9.900 3rd Qu.: 4.650 3rd Qu.:1.900 3rd Qu.:0.4000
## Max. :28.600 Max. :12.200 Max. :5.100 Max. :2.6000
## STL PF TO '+/-
## Min. :0.000 Min. :0.000 Min. :0.000 Min. :-27.6000
## 1st Qu.:0.400 1st Qu.:1.000 1st Qu.:0.800 1st Qu.: -3.6500
## Median :0.800 Median :1.700 Median :1.400 Median : -0.4000
## Mean :1.018 Mean :1.697 Mean :1.767 Mean : -0.4064
## 3rd Qu.:1.500 3rd Qu.:2.300 3rd Qu.:2.450 3rd Qu.: 2.8000
## Max. :5.200 Max. :4.200 Max. :6.700 Max. : 30.0000
## FG% 2PTFG% 3PTFG% FT%
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
## 1st Qu.: 32.10 1st Qu.: 36.55 1st Qu.: 0.00 1st Qu.: 41.45
## Median : 39.00 Median : 46.70 Median : 20.00 Median : 57.10
## Mean : 38.92 Mean : 45.01 Mean : 19.45 Mean : 53.17
## 3rd Qu.: 46.35 3rd Qu.: 54.90 3rd Qu.: 28.80 3rd Qu.: 71.40
## Max. :100.00 Max. :100.00 Max. :100.00 Max. :100.00
## FGA 2PTFGA 3PTFGA FTA
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
## 1st Qu.: 19.50 1st Qu.: 11.70 1st Qu.: 3.10 1st Qu.: 4.00
## Median : 45.10 Median : 27.30 Median : 11.00 Median : 12.00
## Mean : 58.12 Mean : 38.28 Mean : 19.82 Mean : 18.75
## 3rd Qu.: 83.00 3rd Qu.: 55.40 3rd Qu.: 27.50 3rd Qu.: 25.60
## Max. :330.40 Max. :252.00 Max. :166.40 Max. :137.20
### Distribution of Average Stats
hist(df$PTS)

hist(df$REB)

hist(df$AST)

hist(df$BLK)

hist(df$STL)

hist(df$PF)

hist(df$TO)

### Average points of players by teams
boxplot(PTS ~ Teams, data = df,
main = "Points by Teams",
xlab = "Teams",
ylab = "Points",
las = 2)

### Average rebounds of players by teams
boxplot(REB ~ Teams, data = df,
main = "Rebounds by Teams",
xlab = "Teams",
ylab = "Rebounds",
las = 2)

### Average assists of players by teams
boxplot(AST ~ Teams, data = df,
main = "Assists by Teams",
xlab = "Teams",
ylab = "Assists",
las = 2)

### Average blocks of players by teams
boxplot(BLK ~ Teams, data = df,
main = "Blocks by Teams",
xlab = "Teams",
ylab = "Blocks",
las = 2)

### Average steals of players by teams
boxplot(STL ~ Teams, data = df,
main = "Steals by Teams",
xlab = "Teams",
ylab = "Steals",
las = 2)

### Top 10 scorers
top_scorers <- df[order(-df$PTS), ][1:10, ]
barplot(top_scorers$PTS,
names.arg = top_scorers$Player,
main = "Top 10 Scorers",
las = 2)

### Top 10 rebounders
top_rebounders <- df[order(-df$REB), ][1:10, ]
barplot(top_scorers$REB,
names.arg = top_rebounders$Player,
main = "Top 10 Rebounders",
las = 2)

### Top 10 playmakers(assist leaders)
top_playmakers <- df[order(-df$AST), ][1:10, ]
barplot(top_playmakers$AST,
names.arg = top_playmakers$Player,
main = "Top 10 Playmakers",
las = 2)

### Average points per game vs average turnovers per game
plot(df$PTS, df$TO,
main = "Points vs Turnovers",
xlab = "Points",
ylab = "Turnovers")

### Average assists per game vs average turnovers per game
plot(df$AST, df$TO,
main = "Assists vs Turnovers",
xlab = "Assists",
ylab = "Turnovers")
