library(tidyverse)
library(jsonlite)
library(janitor)
library(corrplot)
dates <- c("10/19",
           "10/21",
           "10/22",
           "10/24",
           "10/26",
           "10/28",
           "10/30",
           "11/3",
           "11/5",
           "11/7",
           "11/9",
           "11/11",
           "11/13",
           "11/22",
           "11/23",
           "11/25",
           "11/28",
           "11/30",
           "12/2",
           "12/4",
           "12/6",
           "12/8",
           "12/10",
           "12/14",
           "12/16",
           "12/18",
           "12/20",
           "12/23",
           "12/25",
           "12/27",
           "12/28",
           "12/30",
           "1/1",
           "1/2",
           "1/5",
           "1/6",
           "1/9",
           "1/11",
           "1/15",
           "1/17",
           "1/18",
           "1/24",
           "1/28",
           "1/31",
           "2/2",
           "2/4",
           "2/7",
           "2/9",
           "2/11",
           "2/13",
           "2/15",
           "2/23",
           "2/25",
           "2/26",
           "2/28",
           "3/3",
           "3/6",
           "3/8",
           "3/10",
           "3/12",
           "3/14",
           "3/16",
           "3/18",
           "3/19",
           "3/22",
           "3/25",
           "3/27",
           "4/4",
           "4/8") %>%
  as.data.frame() %>%
  mutate( season = "Regular")

names(dates)[names(dates) == '.'] <- 'date'

dates2 <- c("4/16",
            "4/19",
            "4/21",
            "4/23",
            "4/25",
            "4/29",
            "5/1",
            "5/5",
            "5/7",
            "5/9",
            "5/11",
            "5/16",
            "5/18",
            "5/20",
            "5/22",
            "6/1",
            "6/4",
            "6/7",
            "6/9",
            "6/12") %>%
  as.data.frame() %>%
  mutate(season = "Playoffs")

names(dates2)[names(dates2) == '.'] <- 'date'
team_passes <- c(307,
                 320,
                 333,
                 347,
                 306,
                 289,
                 310,
                 312,
                 293,
                 282,
                 264,
                 267,
                 313,
                 303,
                 396,
                 292,
                 306,
                 287,
                 333,
                 301,
                 303,
                 292,
                 273,
                 276,
                 306,
                 341,
                 334,
                 294,
                 336,
                 344,
                 302,
                 320,
                 286,
                 265,
                 304,
                 265,
                 321,
                 309,
                 308,
                 306,
                 250,
                 308,
                 293,
                 302,
                 284,
                 289,
                 311,
                 282,
                 293,
                 312,
                 289,
                 277,
                 293,
                 320,
                 304,
                 273,
                 256,
                 287,
                 281,
                 281,
                 219,
                 269,
                 287,
                 287,
                 275,
                 273,
                 313,
                 284,
                 342,
                 274,
                 279,
                 305,
                 294,
                 291,
                 240,
                 273,
                 284,
                 269,
                 276,
                 323,
                 284,
                 298,
                 279,
                 288,
                 293,
                 293,
                 250,
                 271,
                 273)

jokic_passes <- c(77,
                  80,
                  96,
                  78,
                  73,
                  61,
                  74,
                  77,
                  59,
                  65,
                  38,
                  50,
                  81,
                  80,
                  96,
                  61,
                  59,
                  69,
                  88,
                  78,
                  77,
                  70,
                  67,
                  66,
                  79,
                  98,
                  88,
                  76,
                  101,
                  97,
                  68,
                  80,
                  70,
                  70,
                  56,
                  71,
                  91,
                  68,
                  83,
                  84,
                  57,
                  93,
                  92,
                  99,
                  85,
                  76,
                  62,
                  73,
                  78,
                  79,
                  80,
                  76,
                  58,
                  81,
                  67,
                  83,
                  73,
                  73,
                  74,
                  71,
                  58,
                  73,
                  81,
                  85,
                  77,
                  60,
                  87,
                  58,
                  68,
                  57,
                  88,
                  88,
                  84,
                  92,
                  53,
                  88,
                  91,
                  69,
                  76,
                  92,
                  95,
                  92,
                  78,
                  108,
                  78,
                  66,
                  75,
                  79,
                  83)
pbp_url_jok <- "https://api.pbpstats.com/get-game-logs/nba?Season=2022-23&SeasonType=Regular%2BSeason&EntityId=203999&EntityType=Player"


pbp_jok <- read_json(pbp_url_jok)



jok_df <- pbp_jok[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>% 
  select(
    on_off_rtg,
    on_def_rtg
  )

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


pbp_jokP <- read_json(pbp_url_jokP)


jokP_df <- pbp_jokP[["multi_row_table_data"]] %>%
  bind_rows() %>%
  clean_names() %>% 
  select(
    on_off_rtg,
    on_def_rtg
  )

jok_on <- rbind(jok_df, jokP_df)

Jokic ’22 passing matrix

jok_passing <- rbind(dates,dates2) %>%
  cbind(team_passes) %>%
  cbind(jokic_passes) %>%
  mutate( '%of_team_passes' = jokic_passes/team_passes) %>%
  cbind(jok_on) 

jok_clean <- jok_passing %>%
  subset( , select = -c(season,date))
corr_J <- cor(as.matrix(jok_clean))

corrplot(corr_J, method = "circle",
          title = "Jokic Passing",
         mar=c(0,0,1,0))

Jokic playoff passing matrix

jok_passing_playoffs <- rbind(dates,dates2) %>%
  cbind(team_passes) %>%
  cbind(jokic_passes) %>%
  mutate( '%of_team_passes' = jokic_passes/team_passes) %>%
  cbind(jok_on) %>%
  filter(season == "Playoffs")

jok_cleanP <- jok_passing_playoffs %>%
  subset( , select = -c(season,date))
corr_JP <- cor(as.matrix(jok_cleanP))

corrplot(corr_JP, method = "circle",
          title = "Jokic Passing - Playoffs",
         mar=c(0,0,1,0))

Jokic regular season passing matrix

jok_passing_regular <- rbind(dates,dates2) %>%
  cbind(team_passes) %>%
  cbind(jokic_passes) %>%
  mutate( '%of_team_passes' = jokic_passes/team_passes) %>%
  cbind(jok_on) %>%
  filter(season == "Regular")

jok_cleanR <- jok_passing_regular %>%
  subset( , select = -c(season,date))
corr_JR <- cor(as.matrix(jok_cleanR))

corrplot(corr_JR, method = "circle",
          title = "Jokic Passing - Regular",
         mar=c(0,0,1,0))