shots_data <- read_csv("shots_data.csv")
## Rows: 504 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): team
## dbl (3): x, y, fgmade
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ggplot(shots_data, aes(x=x, y=y, color = team))+geom_point()

Shot_Distance <- shots_data %>%
  mutate(distance = sqrt(x^2+y^2)) %>%
  mutate(abs_x = abs(x), abs_y=abs(y)) 

corner_threes <- Shot_Distance %>%
 mutate(abs_x = abs(x), abs_y=abs(y)) %>%
  filter(distance>22 & abs_y <=7.8)
ggplot(corner_threes, aes(x=x, y=y, color=team))+geom_point()

non_corner_threes <- Shot_Distance %>%
 filter(distance>=23.75 & y >7.8)
ggplot(non_corner_threes, aes(x=x, y=y, color = team))+geom_point()

two_point_shots <- Shot_Distance %>%
  filter(ifelse(y<=7.8, distance < 22, distance < 23.75))
ggplot(two_point_shots, aes(x=x, y=y, color=team))+geom_point()

TeamA_Shots <- shots_data %>%
  filter(team == "Team A")
TeamA_2PT <- two_point_shots %>%
  filter(team == "Team A")
count(TeamA_Shots)
## # A tibble: 1 × 1
##       n
##   <int>
## 1   280
count(TeamA_2PT)
## # A tibble: 1 × 1
##       n
##   <int>
## 1   194
194/280
## [1] 0.6928571
TeamA_NC3 <- non_corner_threes %>%
  filter(team == "Team A")
count(TeamA_NC3)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    68
68/280
## [1] 0.2428571
TeamA_Corner3 <- corner_threes %>%
  filter(team == "Team A")
count(TeamA_Corner3)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    18
18/280
## [1] 0.06428571
TeamA_2PT_Makes <-TeamA_2PT %>%
  filter(fgmade == "1")
count(TeamA_2PT_Makes)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    95
95/194
## [1] 0.4896907
TeamA_NC3_Makes <- TeamA_NC3 %>%
  filter(fgmade == "1")
count(TeamA_NC3_Makes)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    21
(21+.5*21)/68
## [1] 0.4632353
TeamA_Corner3_Makes <- TeamA_Corner3 %>%
  filter(fgmade == "1")
count(TeamA_Corner3_Makes)
## # A tibble: 1 × 1
##       n
##   <int>
## 1     9
(9+9*.5)/18
## [1] 0.75
TeamB_Shots <- shots_data %>%
  filter(team == "Team B")
TeamB_2PT <- two_point_shots %>%
  filter(team == "Team B")
count(TeamB_Shots)
## # A tibble: 1 × 1
##       n
##   <int>
## 1   224
count(TeamB_2PT)
## # A tibble: 1 × 1
##       n
##   <int>
## 1   150
150/224
## [1] 0.6696429
TeamB_NC3 <- non_corner_threes %>%
  filter(team == "Team B")
count(TeamB_NC3)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    62
62/224
## [1] 0.2767857
TeamB_Corner3 <- corner_threes %>%
  filter(team == "Team B")
count(TeamB_Corner3)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    12
12/224
## [1] 0.05357143
TeamB_2PT_Makes <-TeamB_2PT %>%
  filter(fgmade == "1")
count(TeamB_2PT_Makes)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    67
count(TeamB_2PT)
## # A tibble: 1 × 1
##       n
##   <int>
## 1   150
67/150
## [1] 0.4466667
TeamB_NC3_Makes <- TeamB_NC3 %>%
  filter(fgmade == "1")
count(TeamB_NC3_Makes)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    21
count(TeamB_NC3)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    62
(21+.5*21)/62
## [1] 0.5080645
TeamB_Corner3_Makes <- TeamB_Corner3 %>%
  filter(fgmade == "1")
count(TeamB_Corner3_Makes)
## # A tibble: 1 × 1
##       n
##   <int>
## 1     4
count(TeamB_Corner3)
## # A tibble: 1 × 1
##       n
##   <int>
## 1    12
(4+4*.5)/12
## [1] 0.5