team_colors <- c("#CE1141", "#FDB927", "#6f263d")
justmj<-filter(goat, player == "Michael Jordan")
justkb<-filter(goat, player == "Kobe Bryant")
justlj<-filter(goat, player == "Lebron James")
goat %>%
ggplot(aes(x=year, y=overallbpm, color=player))+
geom_jitter(size=2)+
scale_colour_manual(values = team_colors,
breaks=c('Michael Jordan', 'Kobe Bryant', 'Lebron James'),
labels=c('Michael Jordan', 'Kobe Bryant', 'LeBron James'))+
theme_bw()+
geom_hline(yintercept = 15, linetype="dotted")+
labs(
title="Box Plus/Minus (BPM): Michael Jordan v. Kobe Bryant v. Lebron James",
caption="Box Plus/Minus (BPM) is a basketball box score-based metric that estimates a
basketball player's contribution to the team when that player is on the court.",
y="BPM",
x=""
)
I changed the year to year played so we can analyse side by side. Jen clarified the years in which the stats are lower in her slides to show maybe why they are lower in certain years.
regmj <- filter(goat, player == "Michael Jordan" , gametype == "Regular Season")
mj_regnum <- tibble::rowid_to_column(regmj,"num_year")
playmj<-filter(goat, player == "Michael Jordan" , gametype == "Playoffs")
mj_playnum <- tibble::rowid_to_column(playmj,"num_year")
regkb<-filter(goat, player == "Kobe Bryant" , gametype == "Regular Season")
kb_regnum <- tibble::rowid_to_column(regkb,"num_year")
playkb <- filter(goat, player == "Kobe Bryant" , gametype == "Playoffs")
kb_playnum <- tibble::rowid_to_column(playkb,"num_year")
reglj<-filter(goat, player == "Lebron James", gametype == "Regular Season")
lj_regnum <- tibble::rowid_to_column(reglj,"num_year")
playlj<-filter(goat, player == "Lebron James", gametype == "Playoffs")
lj_playnum <- tibble::rowid_to_column(playlj,"num_year")
index_goat <- rbind(mj_regnum, mj_playnum,kb_regnum,kb_playnum,lj_regnum,lj_playnum)
#view(index_goat)
#This was to write it in the cloud to use!
#write.csv(index_goat, file = "index_goat.csv")
bullsred = "#CE1141"
lakeryellow = "#FDB927"
cavswine = "#6f263d"
team_colors <- c("#CE1141", "#FDB927", "#6f263d")
player_playBMI<- index_goat %>% filter(gametype == "Playoffs")%>%
ggplot(aes(x=num_year, y=overallbpm, color = player))+
geom_line( alpha = .8)+
geom_point()+
scale_colour_manual(values = team_colors,
breaks=c('Michael Jordan', 'Kobe Bryant', 'Lebron James'),
labels=c('Michael Jordan', 'Kobe Bryant', 'LeBron James'))+
theme_bw()+
theme(
plot.caption=element_text(size=8,hjust = 0))+
scale_x_continuous(breaks = seq(0,24,2))+
labs(
title="Michael Jordan v. Kobe Bryant v. Lebron James",
subtitle="Box Plus/Minus (Playoffs BPM) - how do they compare?",
caption="Box Plus/Minus (Playoffs BPM) is a basketball box score-based metric that estimates a basketball player's contribution
to the team when that player is on the court for the playoffs.s.",
color="Player",
y="Playoffs BPM",
x="years played"
)
player_regBMI<- index_goat %>% filter(gametype == "Regular Season")%>%
ggplot(aes(x=num_year, y=overallbpm, color = player))+
geom_line( alpha = .8)+
geom_point()+
scale_colour_manual(values = team_colors,
breaks=c('Michael Jordan', 'Kobe Bryant', 'Lebron James'),
labels=c('Michael Jordan', 'Kobe Bryant', 'LeBron James'))+
scale_x_continuous(breaks = seq(0,24,2))+
theme_bw()+
theme(
plot.caption=element_text(size=8,hjust = 0)
)+
labs(
title="Michael Jordan v. Kobe Bryant v. Lebron James",
subtitle="Box Plus/Minus (Regular Season BPM) - how do they compare?",
caption="Box Plus/Minus (Regular Season BPM) is a basketball box score-based metric that estimates a basketball player's contribution
to the team when that player is on the court for the Regular Season",
color="Player",
y="Regular Season BPM",
x="years played"
)
plot(player_playBMI)
plot(player_regBMI)
# Shiny App code
Here is the code and app!
library(shiny)
library(shinyWidgets)
library(tidyverse)
index_goat$gameplayer <- paste(index_goat$gametype,index_goat$player, sep= " ")
bullsred = "#CE1141"
lakeryellow = "#FDB927"
cavswine = "#6f263d"
team_colors <- c("#CE1141", "#FDB927", "#6f263d")
ui <- fluidPage( titlePanel("Michael Jordan v. Kobe Bryant v. Lebron James"),
sidebarPanel("Players",
checkboxGroupInput(
"players", label = "Please choose Player. ",
choices = list("Michael Jordan" = 'Michael Jordan',
"Kobe Bryant" = 'Kobe Bryant',
"Lebron James" = 'Lebron James'),
selected = 'Michael Jordan'),
pickerInput("gametype","Choose which game type. ", choices=c("Regular Season", "Playoffs"),selected = 'Regular Season', options = list(`actions-box` = FALSE),multiple = T),width=12),
mainPanel('Box Plus/Minus (Playoffs BPM) - how do they compare?',
plotOutput('goatplot'),
position = 'center',
width = 12))
server <- function(input, output){
output$goatplot <-renderPlot(
{
index_goat%>%
filter(gametype %in% input$gametype & player %in% input$players)%>%
# filter(gametype == "Regular Season" & (player == "Michael Jordan" | player == "Kobe Bryant"))%>%
ggplot(aes(x=num_year, y=overallbpm,color=player, groups = gameplayer))+
geom_line( alpha = .8)+
geom_point()+
facet_wrap(~gameplayer)+
facet_grid(~gametype)+
scale_colour_manual(values = team_colors,
breaks=c('Michael Jordan', 'Kobe Bryant', 'Lebron James'),
labels=c('Michael Jordan', 'Kobe Bryant', 'LeBron James'))+
ylim(-6, 20)+
xlim(0,20)+
theme_minimal()+
theme(
plot.caption=element_text(size=8,hjust = 0))+
labs(
caption="Box Plus/Minus (Playoffs BPM) is a basketball box score-based metric that estimates a basketball player's contribution
to the team when that player is on the court for the playoffs",
color="Player",
y="Playoffs BPM",
x="years played"
)
}
)
}
shinyApp(ui = ui, server = server)