Expected points was determined by multiplying a player’s season fg% for a given zone by the value of a made shot from that zone.

  • If a player shoots 36% from the right corner 3, than the expected point formula would be: 3 * .36

  • Expected Free throw points utilizes player’s career ft% instead of just this season.

library(tidyverse)
library(nbastatR)
library(plyr)
library(dplyr)
library(reactable)
library(reactablefmtr)
library(jsonlite)
library(janitor)
library(purrr)
library(rvest)

Sys.setenv("VROOM_CONNECTION_SIZE" = 131072 * 2)
pbp_url_team <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=1610612743&EntityType=Team"


pbp_team <- read_json(pbp_url_team)

team_df <- pbp_team[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() 

pbp_url_opp <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=1610612743&EntityType=Opponent"

pbp_opp <- read_json(pbp_url_opp)

opp_df <- pbp_opp[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names()
team_points <- team_df %>%
  select(date,
         ft_points,
         points)
opp_points <- opp_df %>%
  mutate( opp_points = points) %>%
  select(date,
         opp_points)
nugs_results <- right_join(team_points,opp_points) %>%
  mutate( result = points - opp_points) %>%
  select(date,
         result,
         ft_points)
#Jeff Green
pbp_url_1 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=201145&EntityType=Player"

pbp_1 <- read_json(pbp_url_1)

df_1 <- pbp_1[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( expected_ft_points = fta * .803,
          'Jeff Green' = expected_ft_points) %>%
  select(date,
         'Jeff Green') %>%
  drop_na()
#DeAndre Jordan
pbp_url_2 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=201599&EntityType=Player"

pbp_2 <- read_json(pbp_url_2)

df_2 <- pbp_2[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( 'DeAndre Jordan' = fta * .475) %>%
  select(date,
         'DeAndre Jordan') %>%
  drop_na()
#Kentavious Caldwell-Pope
pbp_url_5 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=203484&EntityType=Player"

pbp_5 <- read_json(pbp_url_5)

df_5 <- pbp_5[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( 'Kentavious Caldwell-Pope' = fta * .814) %>%
  select(date,
         'Kentavious Caldwell-Pope') %>%
  drop_na()
#Aaron Gordon
pbp_url_6 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=203932&EntityType=Player"

pbp_6 <- read_json(pbp_url_6)

df_6 <- pbp_6[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( 'Aaron Gordon' = fta * .687) %>%
  select(date,
         'Aaron Gordon') %>%
  drop_na()
#Nikola Jokic
pbp_url_7 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=203999&EntityType=Player"

pbp_7 <- read_json(pbp_url_7)

df_7 <- pbp_7[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( 'Nikola Jokic' = fta * .829) %>%
  select(date,
         'Nikola Jokic') %>%
  drop_na()
#Jamal Murray
pbp_url_8 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=1627750&EntityType=Player"

pbp_8 <- read_json(pbp_url_8)

df_8 <- pbp_8[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( 'Jamal Murray' = fta * .87) %>%
  select(date,
         'Jamal Murray') %>%
  drop_na()
#Bruce Brown
pbp_url_12 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=1628971&EntityType=Player"

pbp_12 <- read_json(pbp_url_12)

df_12 <- pbp_12[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( 'Bruce Brown' = fta * .749) %>%
  select(date,
         'Bruce Brown') %>%
  drop_na()
#Michael Porter Jr
pbp_url_13 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=1629008&EntityType=Player"

pbp_13 <- read_json(pbp_url_13)

df_13 <- pbp_13[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( 'Michael Porter Jr.' = fta * .749) %>%
  select(date,
         'Michael Porter Jr.') %>%
  drop_na()
#Christian Braun
pbp_url_16 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=1631128&EntityType=Player"

pbp_16 <- read_json(pbp_url_16)

df_16 <- pbp_16[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>%
  filter( team == "DEN") %>%
  mutate( 'Christian Braun' = fta * .625) %>%
  select(date,
         'Christian Braun') %>%
  drop_na()
exp_ft <- left_join(nugs_results, df_1) %>%
  left_join(df_2) %>%
  left_join(df_5) %>%
  left_join(df_6) %>%
  left_join(df_7) %>%
  left_join(df_8) %>%
  left_join(df_12) %>%
  left_join(df_13) %>%
  left_join(df_16) 

exp_ft[is.na(exp_ft)] <- 0

exp_ft$'Exp. Total' <- exp_ft$'Jeff Green' +
  exp_ft$'DeAndre Jordan' +
  exp_ft$'Kentavious Caldwell-Pope' +
  exp_ft$'Aaron Gordon' +
  exp_ft$'Nikola Jokic' +
  exp_ft$'Jamal Murray' +
  exp_ft$'Bruce Brown' +
  exp_ft$'Christian Braun' +
  exp_ft$'Michael Porter Jr.'

exp_ft$'Free throw luck' <- exp_ft$ft_points - exp_ft$'Exp. Total'

exp_ft <- exp_ft %>%
  mutate( 'win/loss' = case_when(
    result > 0 ~ "Win",
    result < 0 ~ "Loss",
  ))

exp_ft_table <- exp_ft %>%
  select(
    date,
    'win/loss',
    'Free throw luck',
    ft_points,
    'Exp. Total'
  ) %>%
  mutate_at(vars(`Free throw luck`,
                 `Exp. Total`), funs(round(.,2)))
pbp_url_team2 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=1610612743&EntityType=Team"

pbp_team2 <- read_json(pbp_url_team2)

team_df2 <- pbp_team2[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() 

pbp_url_opp2 <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Playoffs&EntityId=1610612743&EntityType=Opponent"

pbp_opp2 <- read_json(pbp_url_opp2)

opp_df2 <- pbp_opp2[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names()
team_points2 <- team_df2 %>%
  mutate( fg_points = points - ft_points) %>%
  select(date,
         fg_points, 
         points)

opp_points2 <- opp_df2 %>%
  mutate( opp_fg_points = points - ft_points,
          opp_points = points) %>%
  select(date,
         opp_fg_points,
         opp_points)

nugs_results2 <- right_join(team_points2,opp_points2) %>%
  mutate( result = points - opp_points) %>%
  select(date,
         fg_points,
         result)

nugs_results2$date <- gsub("-", "", as.character(nugs_results2$date))

nugs_results2 <- nugs_results2 %>%
  mutate(dateGame = date)
nuggets_shots_23 <- teams_shots(
  teams = "Denver Nuggets",
  seasons = 2023,
  season_types = "Playoffs",
  return_message = FALSE
)
player_1 <- nuggets_shots_23 %>%
  filter(namePlayer == "Aaron Gordon")

abb3_1 <- player_1 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_1 <- player_1 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_1 <- player_1 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_1 <- player_1 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_1 <- player_1 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_1 <- player_1 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_1_exp_points <- player_1 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .734,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .377,
      zoneBasic == "Mid-Range" ~ 2 * .245,
      zoneBasic == "Above the Break 3" ~ 3 * .407,
      zoneBasic == "Right Corner 3" ~ 3 * .307,
      zoneBasic == "Left Corner 3" ~ 3 * .2,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  replace(is.na(.), 0) %>%
  mutate( 'Aaron Gordon' = expected_points) %>%
  select(dateGame,
         'Aaron Gordon') %>%
  drop_na()
player_2 <- nuggets_shots_23 %>%
  filter(namePlayer == "Christian Braun")

abb3_2 <- player_2 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_2 <- player_2 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_2 <- player_2 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_2 <- player_2 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_2 <- player_2 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_2 <- player_2 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_2_exp_points <- player_2 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .682,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .348,
      zoneBasic == "Mid-Range" ~ 2 * .2,
      zoneBasic == "Above the Break 3" ~ 3 * .321,
      zoneBasic == "Right Corner 3" ~ 3 * .286,
      zoneBasic == "Left Corner 3" ~ 3 * .462,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  replace(is.na(.), 0) %>%
  mutate( 'Christian Braun' = expected_points) %>%
  select(dateGame,
         'Christian Braun') %>%
  drop_na()
player_3 <- nuggets_shots_23 %>%
  filter(namePlayer == "Bruce Brown")

abb3_3 <- player_3 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_3 <- player_3 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_3 <- player_3 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_3 <- player_3 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_3 <- player_3 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_3 <- player_3 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_3_exp_points <- player_3 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .734,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .717,
      zoneBasic == "Mid-Range" ~ 2 * .269,
      zoneBasic == "Above the Break 3" ~ 3 * .351,
      zoneBasic == "Right Corner 3" ~ 3 * .516,
      zoneBasic == "Left Corner 3" ~ 3 * .132,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  replace(is.na(.), 0) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Bruce Brown' = expected_points) %>%
  select(dateGame,
         'Bruce Brown') %>%
  drop_na()
player_5 <- nuggets_shots_23 %>%
  filter(namePlayer == "Kentavious Caldwell-Pope")

abb3_5 <- player_5 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_5 <- player_5 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_5 <- player_5 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_5 <- player_5 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_5 <- player_5 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_5 <- player_5 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_5_exp_points <- player_5 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .628,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .439,
      zoneBasic == "Mid-Range" ~ 2 * .416,
      zoneBasic == "Above the Break 3" ~ 3 * .437,
      zoneBasic == "Right Corner 3" ~ 3 * .411,
      zoneBasic == "Left Corner 3" ~ 3 * .405,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Kentavious Caldwell-Pope' = expected_points) %>%
  select(dateGame,
         'Kentavious Caldwell-Pope') %>%
  drop_na()
player_6 <- nuggets_shots_23 %>%
  filter(namePlayer == "Vlatko Cancar")

abb3_6 <- player_6 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_6 <- player_6 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_6 <- player_6 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_6 <- player_6 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_6 <- player_6 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_6 <- player_6 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_6_exp_points <- player_6 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .696,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .352,
      zoneBasic == "Mid-Range" ~ 2 * .556,
      zoneBasic == "Above the Break 3" ~ 3 * .347,
      zoneBasic == "Right Corner 3" ~ 3 * .444,
      zoneBasic == "Left Corner 3" ~ 3 * .433,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Vlatko Cancar' = expected_points) %>%
  select(dateGame,
         'Vlatko Cancar') %>%
  drop_na()
player_8 <- nuggets_shots_23 %>%
  filter(namePlayer == "Reggie Jackson")

abb3_8 <- player_8 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_8 <- player_8 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_8 <- player_8 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_8 <- player_8 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_8 <- player_8 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_8 <- player_8 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_8_exp_points <- player_8 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .615,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .536,
      zoneBasic == "Mid-Range" ~ 2 * .368,
      zoneBasic == "Above the Break 3" ~ 3 * .256,
      zoneBasic == "Right Corner 3" ~ 3 * .437,
      zoneBasic == "Left Corner 3" ~ 3 * 0,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Reggie Jackson' = expected_points) %>%
  select(dateGame,
         'Reggie Jackson') %>%
  drop_na()
player_7 <- nuggets_shots_23 %>%
  filter(namePlayer == "Jeff Green")

abb3_7 <- player_7 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_7 <- player_7 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_7 <- player_7 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_7 <- player_7 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_7 <- player_7 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_7 <- player_7 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_7_exp_points <- player_7 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .677,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .5,
      zoneBasic == "Mid-Range" ~ 2 * .321,
      zoneBasic == "Above the Break 3" ~ 3 * .219,
      zoneBasic == "Right Corner 3" ~ 3 * .45,
      zoneBasic == "Left Corner 3" ~ 3 * .389,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Jeff Green' = expected_points) %>%
  select(dateGame,
         'Jeff Green') %>%
  drop_na()
player_9 <- nuggets_shots_23 %>%
  filter(namePlayer == "Nikola Jokic")

abb3_9 <- player_9 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_9 <- player_9 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_9 <- player_9 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_9 <- player_9 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_9 <- player_9 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_9 <- player_9 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_9_exp_points <- player_9 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .745,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .627,
      zoneBasic == "Mid-Range" ~ 2 * .523,
      zoneBasic == "Above the Break 3" ~ 3 * .397,
      zoneBasic == "Right Corner 3" ~ 3 * .25,
      zoneBasic == "Left Corner 3" ~ 3 * 0,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Nikola Jokic' = expected_points) %>%
  select(dateGame,
         'Nikola Jokic') %>%
  drop_na()
player_10 <- nuggets_shots_23 %>%
  filter(namePlayer == "DeAndre Jordan")

abb3_10 <- player_10 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_10 <- player_10 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_10 <- player_10 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_10 <- player_10 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_10 <- player_10 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_10 <- player_10 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_10_exp_points <- player_10 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .816,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .222,
      zoneBasic == "Mid-Range" ~ 2 * .5,
      zoneBasic == "Above the Break 3" ~ 3 * 1,
      zoneBasic == "Right Corner 3" ~ 3 * 0,
      zoneBasic == "Left Corner 3" ~ 3 * 0,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  replace(is.na(.), 0) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'DeAndre Jordan' = expected_points) %>%
  select(dateGame,
         'DeAndre Jordan') %>%
  drop_na()
player_11 <- nuggets_shots_23 %>%
  filter(namePlayer == "Jamal Murray")

abb3_11 <- player_11 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_11 <- player_11 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_11 <- player_11 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_11 <- player_11 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_11 <- player_11 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_11 <- player_11 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_11_exp_points <- player_11 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .654,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .412,
      zoneBasic == "Mid-Range" ~ 2 * .411,
      zoneBasic == "Above the Break 3" ~ 3 * .39,
      zoneBasic == "Right Corner 3" ~ 3 * .5,
      zoneBasic == "Left Corner 3" ~ 3 * .515,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Jamal Murray' = expected_points) %>%
  select(dateGame,
         'Jamal Murray') %>%
  drop_na()
player_12 <- nuggets_shots_23 %>%
  filter(namePlayer == "Zeke Nnaji")

abb3_12 <- player_12 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_12 <- player_12 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_12 <- player_12 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_12 <- player_12 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_12 <- player_12 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_12 <- player_12 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_12_exp_points <- player_12 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .742,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .333,
      zoneBasic == "Mid-Range" ~ 2 * .5,
      zoneBasic == "Above the Break 3" ~ 3 * .282,
      zoneBasic == "Right Corner 3" ~ 3 * .286,
      zoneBasic == "Left Corner 3" ~ 3 * .2,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Zeke Nnaji' = expected_points) %>%
  select(dateGame,
         'Zeke Nnaji') %>%
  drop_na()
player_13 <- nuggets_shots_23 %>%
  filter(namePlayer == "Michael Porter Jr.")

abb3_13 <- player_13 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_13 <- player_13 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_13 <- player_13 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_13 <- player_13 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_13 <- player_13 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_13 <- player_13 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_13_exp_points <- player_13 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .757,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .414,
      zoneBasic == "Mid-Range" ~ 2 * .424,
      zoneBasic == "Above the Break 3" ~ 3 * .387,
      zoneBasic == "Right Corner 3" ~ 3 * .601,
      zoneBasic == "Left Corner 3" ~ 3 * .5,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Michael Porter Jr.' = expected_points) %>%
  select(dateGame,
         'Michael Porter Jr.') %>%
  drop_na()
player_14 <- nuggets_shots_23 %>%
  filter(namePlayer == "Ish Smith")

abb3_14 <- player_14 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_14 <- player_14 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_14 <- player_14 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_14 <- player_14 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_14 <- player_14 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_14 <- player_14 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_14_exp_points <- player_14 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .565,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .444,
      zoneBasic == "Mid-Range" ~ 2 * .371,
      zoneBasic == "Above the Break 3" ~ 3 * .111,
      zoneBasic == "Right Corner 3" ~ 3 * 0,
      zoneBasic == "Left Corner 3" ~ 3 * 0,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  mutate( 'Ish Smith' = expected_points) %>%
  select(dateGame,
         'Ish Smith') %>%
  drop_na()
player_15 <- nuggets_shots_23 %>%
  filter(namePlayer == "Peyton Watson")

abb3_15 <- player_15 %>%
  filter( zoneBasic == "Above the Break 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot)) %>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( abb3_pct = accuracy * 100,
          zone = "Above the Break 3")

  

lc3_15 <- player_15 %>%
  filter( zoneBasic == "Left Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( lc3_pct = accuracy * 100,
          zone = "Left Corner 3")


mr_15 <- player_15 %>%
  filter( zoneBasic == "Mid-Range") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( mr_pct = accuracy * 100,
          zone = "Mid-Range")


rc3_15 <- player_15 %>%
  filter( zoneBasic == "Right Corner 3") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( rc3_pct = accuracy * 100,
          zone = "Right Corner 3")


ip_15 <- player_15 %>%
  filter( zoneBasic == "In The Paint (Non-RA)") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ip_pct = accuracy * 100,
          zone = "In the Paint (non RA)")


ra_15 <- player_15 %>%
  filter( zoneBasic == "Restricted Area") %>%
  summarise( accuracy = mean(isShotMade),
             shots = sum(isShotAttempted),
             makes = sum(isShotMade),
             avg_distance = mean(distanceShot))%>%
  mutate_at(vars(accuracy, avg_distance), funs(round(.,4))) %>%
  mutate( ra_1 = accuracy * 100,
          zone = "Restricted Area")

player_15_exp_points <- player_15 %>%
  mutate(
    expected_points = case_when(
      zoneBasic == "Restricted Area" ~ 2 * .571,
      zoneBasic == "In The Paint (Non-RA)" ~ 2 * .5,
      zoneBasic == "Mid-Range" ~ 2 * .2,
      zoneBasic == "Above the Break 3" ~ 3 * .375,
      zoneBasic == "Right Corner 3" ~ 3 * 0,
      zoneBasic == "Left Corner 3" ~ 3 * .6,
    )
  ) %>%
  select(namePlayer,
         idGame,
         dateGame,
         expected_points) %>%
  group_by(dateGame) %>%
  summarise_at(vars(expected_points), sum) %>%
  replace(is.na(.), 0) %>%
  mutate( 'Peyton Watson' = expected_points) %>%
  select(dateGame,
         'Peyton Watson') %>%
  drop_na()
exp_points <- left_join(nugs_results2, player_1_exp_points) %>%
  left_join(player_2_exp_points) %>%
  left_join(player_3_exp_points) %>%
  left_join(player_5_exp_points) %>%
  left_join(player_6_exp_points) %>%
  left_join(player_7_exp_points) %>%
  left_join(player_8_exp_points) %>%
  left_join(player_9_exp_points) %>%
  left_join(player_10_exp_points) %>%
  left_join(player_11_exp_points) %>%
  left_join(player_12_exp_points) %>%
  left_join(player_13_exp_points) %>%
  left_join(player_14_exp_points) %>%
  left_join(player_15_exp_points) 
 

exp_points[is.na(exp_points)] <- 0


exp_points$'Exp. Total' <- exp_points$`Aaron Gordon`+
  exp_points$`Christian Braun` +
  exp_points$`Bruce Brown` +
  exp_points$`Kentavious Caldwell-Pope` +
  exp_points$`Vlatko Cancar` +
  exp_points$`Jeff Green` + 
  exp_points$`Reggie Jackson` +
  exp_points$`Nikola Jokic` +
  exp_points$`DeAndre Jordan` +
  exp_points$`Jamal Murray` +
  exp_points$`Zeke Nnaji` +
  exp_points$`Michael Porter Jr.` +
  exp_points$`Ish Smith` +
  exp_points$`Peyton Watson`

exp_points$'Field Goal luck' <- exp_points$fg_points - exp_points$'Exp. Total'

exp_points <- exp_points %>%
  mutate( 'win/loss' = case_when(
    result > 0 ~ "Win",
    result < 0 ~ "Loss",
  ))

exp_table <- exp_points %>%
  select(date,
         fg_points,
         'Exp. Total',
         'Field Goal luck',
         'win/loss') 

Expected Points

exp_table2 <- exp_table %>%
  mutate('Exp. FG total' = `Exp. Total`,
         date2 = date) %>%
  select(date2,
         `Exp. FG total`,
         fg_points,
         `Field Goal luck`,
         'win/loss')

exp_ft_table2 <- exp_ft_table %>%
  mutate('Exp. FT total' = `Exp. Total`) %>%
  select(date,
         `Exp. FT total`,
         ft_points, 
         `Free throw luck`)

table3 <- cbind(exp_table2,exp_ft_table2)

table3$'Total points' <- table3$fg_points + table3$ft_points

table3$'Total Exp. points' <- table3$`Exp. FG total` + table3$`Exp. FT total` 

table3 %>% 
  select(date,
        `win/loss`,
        `Total points`,
        `Total Exp. points`,
        `Field Goal luck`,
        `Free throw luck`) %>%
  mutate_at(vars(`Field Goal luck`), funs(round(.,2))) %>%
  reactable( theme = espn())

Field Goal luck

exp_table %>%
  mutate_at(vars(`Field Goal luck`,
                 `Exp. Total`), funs(round(.,2))) %>%
  reactable(theme = espn())
exp_points %>%
  select(date,
         fg_points,
         `Exp. Total`,
         'Nikola Jokic',
         'Jamal Murray',
         'Aaron Gordon',
         'Michael Porter Jr.',
         'Kentavious Caldwell-Pope',
         'Bruce Brown',
         'Jeff Green',
         'Christian Braun',
         'DeAndre Jordan',
         'Vlatko Cancar',
         'Reggie Jackson',
         'Zeke Nnaji',
         'Ish Smith',
         'Peyton Watson') %>%
  reactable(theme = espn()) %>%
  add_title("Expected FG points by player")

Expected FG points by player

Free throw luck

exp_ft_table %>%
  reactable(theme = espn())
exp_ft %>%
  select(
    date,
    'win/loss',
    ft_points,
    'Exp. Total',
    'Nikola Jokic',
    'Jamal Murray',
    'Aaron Gordon',
    'Michael Porter Jr.',
    'Kentavious Caldwell-Pope',
    'Bruce Brown',
    'Jeff Green',
    'Christian Braun',
    'DeAndre Jordan'
  ) %>%
  reactable( theme = espn()) %>%
  add_title("Expected FT points by player")

Expected FT points by player