Problem : The echoes of the common basketball adage “protect the paint” can be heard vibrating through the halls of gyms and arenas across the country let alone the globe, but is this “truth” actually based upon evidence.

Process : While creating a shooting scouting report for the Lakers, I noticed a stark difference between the field goal percentage of shots taken from within the restricted area and those taken from the paint excluding the restricted area. Using shot data from the 2022 season I was able to find what that difference was for each NBA team last year.

Takeaways:

  • There is a stark difference in the FG% of shots taken from the restricted area and the rest of the paint across the league.

    • Restricted area FG%: 65.42%
    • Paint (non RA) FG%: 42.36%
    • Difference: 23.06%
  • Team dialogue should shift from “protect the paint” to “protect the restricted area”.

  • The magnitude of the difference is not indicative of performance. The measurement is too dependent upon situation to be used as a league wide metric.

  • The combination of restricted area and the rest of the paint FG% does appear to be a good indicator of offense, which strongly aligns with the basic basketball intuition.

library(nbastatR)
library(tidyverse)
library(dplyr)
library(reactable)
library(reactablefmtr)
library(dplyr)
library(ggplot2)
library(plotly)

Sys.setenv("VROOM_CONNECTION_SIZE" = 131072 * 2)

Team Data

Boston Celtics

team <- "Boston Celtics"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Boston Celtics 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_1 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_1$team <- team
summary_1 %>% reactable()
summary_1 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Brooklyn Nets

team <- "Brooklyn Nets"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Brooklyn Nets 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_2 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_2$team <- team
summary_2 %>% reactable()
summary_2 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

New York Knicks

team <- "New York Knicks"
shots <- teams_shots( teams = team,
             seasons = 2022)
## New York Knicks 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_3 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_3$team <- team
summary_3 %>% reactable()
summary_3 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Philadelphia 76ers

team <- "Philadelphia 76ers"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Philadelphia 76ers 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_4 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_4$team <- team
summary_4 %>% reactable()
summary_4 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Toronto Raptors

team <- "Toronto Raptors"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Toronto Raptors 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_5 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_5$team <- team
summary_5 %>% reactable()
summary_5 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Chicago Bulls

team <- "Chicago Bulls"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Chicago Bulls 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_6 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_6$team <- team
summary_6 %>% reactable()
summary_6 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Cleveland Cavaliers

team <- "Cleveland Cavaliers"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Cleveland Cavaliers 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_7 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_7$team <- team
summary_7 %>% reactable()
summary_7 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Detroit Pistons

team <- "Detroit Pistons"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Detroit Pistons 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_8 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_8$team <- team
summary_8 %>% reactable()
summary_8 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Indiana Pacers

team <- "Indiana Pacers"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Indiana Pacers 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_9 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_9$team <- team
summary_9 %>% reactable()
summary_9 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Milwaukee Bucks

team <- "Milwaukee Bucks"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Milwaukee Bucks 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_10 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_10$team <- team
summary_10 %>% reactable()
summary_10 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Atlanta Hawks

team <- "Atlanta Hawks"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Atlanta Hawks 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_11 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_11$team <- team
summary_11 %>% reactable()
summary_11 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Charlotte Hornets

team <- "Charlotte Hornets"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Charlotte Hornets 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_12 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_12$team <- team
summary_12 %>% reactable()
summary_12 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Miami Heat

team <- "Miami Heat"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Miami Heat 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_13 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_13$team <- team
summary_13 %>% reactable()
summary_13 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Orlando Magic

team <- "Orlando Magic"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Orlando Magic 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_14 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_14$team <- team
summary_14 %>% reactable()
summary_14 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Washington Wizards

team <- "Washington Wizards"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Washington Wizards 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_15 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_15$team <- team
summary_15 %>% reactable()
summary_15 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Denver Nuggets

team <- "Denver Nuggets"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Denver Nuggets 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_16 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_16$team <- team
summary_16 %>% reactable()
summary_16 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Minnesota Timberwolves

team <- "Minnesota Timberwolves"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Minnesota Timberwolves 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_17 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_17$team <- team
summary_17 %>% reactable()
summary_17 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Oklahoma City Thunder

team <- "Oklahoma City Thunder"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Oklahoma City Thunder 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_18 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_18$team <- team
summary_18 %>% reactable()
summary_18 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Portland Trail Blazers

team <- "Portland Trail Blazers"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Portland Trail Blazers 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_19 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_19$team <- team
summary_19 %>% reactable()
summary_19 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Utah Jazz

team <- "Utah Jazz"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Utah Jazz 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_20 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_20$team <- team
summary_20 %>% reactable()
summary_20 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Golden State Warriors

team <- "Golden State Warriors"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Golden State Warriors 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_21 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_21$team <- team
summary_21 %>% reactable()
summary_21 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Los Angeles Clippers

team <- "Los Angeles Clippers"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Los Angeles Clippers 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_22 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_22$team <- team
summary_22 %>% reactable()
summary_22 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Los Angeles Lakers

team <- "Los Angeles Lakers"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Los Angeles Lakers 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_23 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_23$team <- team
summary_23 %>% reactable()
summary_23 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Phoenix Suns

team <- "Phoenix Suns"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Phoenix Suns 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_24 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_24$team <- team
summary_24 %>% reactable()
summary_24 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Sacramento Kings

team <- "Sacramento Kings"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Sacramento Kings 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_25 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_25$team <- team
summary_25 %>% reactable()
summary_25 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Dallas Mavericks

team <- "Dallas Mavericks"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Dallas Mavericks 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_26 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_26$team <- team
summary_26 %>% reactable()
summary_26 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Houston Rockets

team <- "Houston Rockets"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Houston Rockets 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_27 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_27$team <- team
summary_27 %>% reactable()
summary_27 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

Memphis Grizzlies

team <- "Memphis Grizzlies"
shots <- teams_shots( teams = team,
             seasons = 2022)
## Memphis Grizzlies 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_28 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_28$team <- team
summary_28 %>% reactable()
summary_28 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

New Orleans Pelicans

team <- "New Orleans Pelicans"
shots <- teams_shots( teams = team,
             seasons = 2022)
## New Orleans Pelicans 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_29 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_29$team <- team
summary_29 %>% reactable()
summary_29 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

San Antonio Spurs

team <- "San Antonio Spurs"
shots <- teams_shots( teams = team,
             seasons = 2022)
## San Antonio Spurs 2021-22 shot data
paint <- shots %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  mutate(isShotAttempted = 1,
         isShotMade = case_when(
           isShotMade == "TRUE" ~ 1,
           TRUE ~ 0
         ))
ra <- shots %>%
  filter(zoneBasic == "Restricted Area" ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade)) %>%
  mutate( distance = "Restricted Area")

non_ra <- paint %>%
  filter(distanceShot >= 5 ) %>%
  summarise( team_accuracy = mean(isShotMade),
             attempts = sum(isShotAttempted),
             makes = sum(isShotMade),
             team = all(nameTeam)) %>%
  mutate( distance = "Paint")

summary_30 <- bind_rows(ra, non_ra) %>% select( team, distance, team_accuracy, makes, attempts) %>%
   mutate_at(vars(team_accuracy), funs(round(.,4)))
summary_30$team <- team
summary_30 %>% reactable()
summary_30 %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

League Data

league_5ft <- bind_rows( summary_1, summary_2, summary_3, summary_4, summary_5, summary_6,summary_7, summary_8, summary_9, summary_10, summary_11, summary_12, summary_13, summary_14, summary_15, summary_16, summary_17, summary_18, summary_19, summary_20, summary_21, summary_22, summary_23, summary_24, summary_25, summary_26, summary_27, summary_28, summary_29, summary_30) %>%
  filter( distance == "Restricted Area") %>%
  summarise( team_accuracy = mean(team_accuracy),
             attempts = sum(attempts),
             makes = sum(makes)) %>%
  mutate_at(vars(team_accuracy), funs(round(.,4))) %>%
  mutate( distance = "Restricted Area")

league_5to15 <- bind_rows( summary_1, summary_2, summary_3, summary_4, summary_5, summary_6,summary_7, summary_8, summary_9, summary_10, summary_11, summary_12, summary_13, summary_14, summary_15, summary_16, summary_17, summary_18, summary_19, summary_20, summary_21, summary_22, summary_23, summary_24, summary_25, summary_26, summary_27, summary_28, summary_29, summary_30) %>%
  filter( distance == "Paint") %>%
  summarise( team_accuracy = mean(team_accuracy),
             attempts = sum(attempts),
             makes = sum(makes)) %>%
  mutate_at(vars(team_accuracy), funs(round(.,4))) %>%
  mutate( distance = "Paint")

final_league <- bind_rows(league_5ft, league_5to15) %>%
  select(distance, team_accuracy, makes, attempts) 
final_league %>% reactable()
final_league %>% ggplot(aes( x = distance , y = team_accuracy, fill = distance)) + geom_col() + geom_text( aes(label = team_accuracy), vjust = 1.5, color = "white")

teams <- c("Boston Celtics", "Brooklyn Nets", "New York Knicks", "Philadelphia 76ers", "Toronto Raptors", "Chicago Bulls", "Cleveland Cavaliers", "Detroit Pistons", "Indiana Pacers", "Milwaukee Bucks", "Atlanta Hawks", "Charlotte Hornets", "Miami Heat", "Orlando Magic", "Washington Wizards", "Denver Nuggets", "Minnesota Timberwolves", "Oklahoma City Thunder", "Portland Trail Blazers", "Utah Jazz", "Golden State Warriors", "Los Angeles Clippers", "Los Angeles Lakers", "Phoenix Suns", "Sacramento Kings", "Dallas Mavericks", "Houston Rockets", "Memphis Grizzlies", "New Orleans Pelicans", "San Antonio Spurs")

difference <- c(.2793, .174, .234, .2514, .1993, .1984, .2615, .2344, .2254, .2604, .2039, .2638, .2151, .2382, .3064, .2203, .2287, .1872, .1875, .2352, .2931, .1941, .2976, .1848, .2457, .2385, .2719, .2138, .1887, .1898)

combined <- c(1.117, 1.0892, 1.005, 1.0748, 1.0613, 1.1052, 1.0727, .9838, 1.0688, 1.0964, 1.0779, 1.0284, 1.0993, 1.0306, 1.0932, 1.1631, 1.0659, 1.0202, 1.0205, 1.1502, 1.1079, 1.1041, 1.042, 1.1848, 1.0673, 1.1489, 1.099, 1.0704, 1.0823, 1.098)
diff_table <- bind_cols(teams, difference) %>% 
  rename(team = '...1',
         difference = '...2') %>%
  arrange(desc(difference))
comb_table <- bind_cols(teams, combined) %>%
  rename( team = '...1',
          combined = '...2') %>%
  arrange(desc(combined))

diff_table %>% reactable( pagination = FALSE,
                          sortable = TRUE) %>%
  add_title("Diffenence in Restricted Area and Paint (non RA) FG%")

Diffenence in Restricted Area and Paint (non RA) FG%

comb_table %>% reactable( pagination = FALSE,
                         sortable = TRUE) %>%
  add_title("Combined Restricted Area and Paint (non RA) FG%")

Combined Restricted Area and Paint (non RA) FG%

league_paint <- bind_rows( summary_1, summary_2, summary_3, summary_4, summary_5, summary_6,summary_7, summary_8, summary_9, summary_10, summary_11, summary_12, summary_13, summary_14, summary_15, summary_16, summary_17, summary_18, summary_19, summary_20, summary_21, summary_22, summary_23, summary_24, summary_25, summary_26, summary_27, summary_28, summary_29, summary_30) %>%
  filter( distance == "Paint") %>%
  arrange(desc(team_accuracy))

league_ra <- bind_rows( summary_1, summary_2, summary_3, summary_4, summary_5, summary_6,summary_7, summary_8, summary_9, summary_10, summary_11, summary_12, summary_13, summary_14, summary_15, summary_16, summary_17, summary_18, summary_19, summary_20, summary_21, summary_22, summary_23, summary_24, summary_25, summary_26, summary_27, summary_28, summary_29, summary_30) %>%
  filter( distance == "Restricted Area") %>%
  arrange(desc(team_accuracy))

league_paint %>% reactable( pagination = FALSE,
                            sortable = TRUE) %>%
  add_title("Paint (non RA) FG%")

Paint (non RA) FG%

league_ra %>% reactable( pagination = FALSE,
                         sortable = TRUE) %>%
  add_title("Restricted Area FG%")

Restricted Area FG%