library(rvest)
library(rebus)
library(stringr)
library(tidyr)
library(dplyr)
library(ggplot2)
library(plotly)
library(crosstalk)
library(lubridate)
#1225
#scrape the rotoguru site
dfs1225 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=12&day=25&year=2020&game=dk")

#extract data table
dfs1225 <- dfs1225 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs1225 <- data.frame(dfs1225)

#remove top row
dfs1225 <- dfs1225[-1,]

#add date column
dfs1225 <- dfs1225 %>%
  mutate(Date = as.POSIXct("2020-12-25"))
#1226
#scrape the rotoguru site
dfs1226 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=12&day=26&year=2020&game=dk")

#extract data table
dfs1226 <- dfs1226 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs1226 <- data.frame(dfs1226)

#remove top row
dfs1226 <- dfs1226[-1,]

#add date column
dfs1226 <- dfs1226 %>%
  mutate(Date = as.POSIXct("2020-12-26"))
#1227
#scrape the rotoguru site
dfs1227 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=12&day=27&year=2020&game=dk")

#extract data table
dfs1227 <- dfs1227 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs1227 <- data.frame(dfs1227)

#remove top row
dfs1227 <- dfs1227[-1,]

#add date column
dfs1227 <- dfs1227 %>%
  mutate(Date = as.POSIXct("2020-12-27"))
#1228
#scrape the rotoguru site
dfs1228 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=12&day=28&year=2020&game=dk")

#extract data table
dfs1228 <- dfs1228 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs1228 <- data.frame(dfs1228)

#remove top row
dfs1228 <- dfs1228[-1,]

#add date column
dfs1228 <- dfs1228 %>%
  mutate(Date = as.POSIXct("2020-12-28")) 
#1229
#scrape the rotoguru site
dfs1229 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=12&day=29&year=2020&game=dk")

#extract data table
dfs1229 <- dfs1229 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs1229 <- data.frame(dfs1229)

#remove top row
dfs1229 <- dfs1229[-1,]

#add date column
dfs1229 <- dfs1229 %>%
  mutate(Date = as.POSIXct("2020-12-29"))
#1230
#scrape the rotoguru site
dfs1230 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=12&day=30&year=2020&game=dk")

#extract data table
dfs1230 <- dfs1230 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs1230 <- data.frame(dfs1230)

#remove top row
dfs1230 <- dfs1230[-1,]

#add date column
dfs1230 <- dfs1230 %>%
  mutate(Date = as.POSIXct("2020-12-30"))
#1231
#scrape the rotoguru site
dfs1231 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=12&day=31&year=2020&game=dk")

#extract data table
dfs1231 <- dfs1231 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs1231 <- data.frame(dfs1231)

#remove top row
dfs1231 <- dfs1231[-1,]

#add date column
dfs1231 <- dfs1231 %>%
  mutate(Date = as.POSIXct("2020-12-31"))
#0101
#scrape the rotoguru site
dfs0101 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=01&day=01&year=2021&game=dk")

#extract data table
dfs0101 <- dfs0101 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs0101 <- data.frame(dfs0101)

#remove top row
dfs0101 <- dfs0101[-1,]

#add date column
dfs0101<- dfs0101 %>%
  mutate(Date = as.POSIXct("2021-01-01"))
#0102
#scrape the rotoguru site
dfs0102 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=01&day=02&year=2021&game=dk")

#extract data table
dfs0102 <- dfs0102 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs0102 <- data.frame(dfs0102)

#remove top row
dfs0102 <- dfs0102[-1,]

#add date column
dfs0102<- dfs0102 %>%
  mutate(Date = as.POSIXct("2021-01-02"))
#0103
#scrape the rotoguru site
dfs0103 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=01&day=03&year=2021&game=dk")

#extract data table
dfs0103 <- dfs0103 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs0103 <- data.frame(dfs0103)

#remove top row
dfs0103 <- dfs0103[-1,]

#add date column
dfs0103 <- dfs0103 %>%
  mutate(Date = as.POSIXct("2021-01-03"))
#0104
#scrape the rotoguru site
dfs0104 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=01&day=04&year=2021&game=dk")

#extract data table
dfs0104 <- dfs0104 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs0104 <- data.frame(dfs0104)

#remove top row
dfs0104 <- dfs0104[-1,]

#add date column
dfs0104 <- dfs0104 %>%
  mutate(Date = as.POSIXct("2021-01-04"))
#0105
#scrape the rotoguru site
dfs0105 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=01&day=05&year=2021&game=dk")

#extract data table
dfs0105 <- dfs0105 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs0105 <- data.frame(dfs0105 )

#remove top row
dfs0105 <- dfs0105[-1,]

#add date column
dfs0105 <- dfs0105 %>%
  mutate(Date = as.POSIXct("2021-01-05"))
#0106
#scrape the rotoguru site
dfs0106 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=01&day=06&year=2021&game=dk")

#extract data table
dfs0106 <- dfs0106 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs0106 <- data.frame(dfs0106)

#remove top row
dfs0106 <- dfs0106[-1,]

#add date column
dfs0106 <- dfs0106 %>%
  mutate(Date = as.POSIXct("2021-01-06"))
#0107
#scrape the rotoguru site
dfs0107 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=01&day=07&year=2021&game=dk")

#extract data table
dfs0107 <- dfs0107 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs0107 <- data.frame(dfs0107)

#remove top row
dfs0107 <- dfs0107[-1,]

#add date column
dfs0107 <- dfs0107 %>%
  mutate(Date = as.POSIXct("2021-01-07"))
#0108
#scrape the rotoguru site
dfs0108 <- read_html("http://rotoguru1.com/cgi-bin/hyday.pl?mon=01&day=08&year=2021&game=dk")

#extract data table
dfs0108 <- dfs0108 %>%
        html_nodes("table") %>%
        .[9] %>%
        html_table(fill = TRUE)

#convert to df
dfs0108 <- data.frame(dfs0108)

#remove top row
dfs0108 <- dfs0108[-1,]

#add date column
dfs0108 <- dfs0108 %>%
  mutate(Date = as.POSIXct("2021-01-08"))
#bind rows
fullframe <- rbind(dfs1225, dfs1226, dfs1227, dfs1228, dfs1229, dfs1230, dfs1231, dfs0101, dfs0102, dfs0103, dfs0104, dfs0105, dfs0106, dfs0107, dfs0108)
#chaning df name to limit need for scraping during testing 
todate <- fullframe
#change col names
colnames(todate)[1] <- "Pos"
colnames(todate)[2] <- "Name"
colnames(todate)[3] <- "Pts"
colnames(todate)[4] <- "Salary"
colnames(todate)[5] <- "Team"
colnames(todate)[6] <- "Opp"
colnames(todate)[7] <- "Score"
colnames(todate)[8] <- "Min"
colnames(todate)[9] <- "Statline"
#remove non player data 
todate <- todate[ grep("RotoGuru", todate$Pos, invert = TRUE) , ]
todate <- todate[ grep("Unlisted", todate$Pos, invert = TRUE) , ]
todate <- todate[ grep("Guards", todate$Pos, invert = TRUE) , ]
todate <- todate[ grep("Centers", todate$Pos, invert = TRUE) , ]
todate <- todate[ grep("Forwards", todate$Pos, invert = TRUE) , ]
todate <- todate[ grep("DNP", todate$Min, invert = TRUE) , ]

#remove na minutes
todate <- todate %>%
        drop_na(Min)
#remove NA's from Position - these are here because the site has NA equivalent to Unlisted
todate$Pos <- ifelse(is.na(todate$Pos), 
             'Unlisted', todate$Pos)
#use gsub to remove $ and comma from monetary values prior to data conversion to numeric (or you will get error)
todate$Salary <- gsub("\\$", "", todate$Salary)
todate$Salary <- gsub("\\,", "", todate$Salary)
#use this chunk to determine if there are any NA values in the binded dataframe - Set eval to TRUE to run 
sapply(todate, function(x) sum(is.na(x)))
#use lapply to convert salary and points to a numeric
todate[, 3:4] <- lapply(todate[, 3:4], as.numeric)
#remove NA's for all unlisted players - still need to know why unlisted
todate <- todate %>%
        drop_na(Salary)
#drop the ^ character - need to use \\ to drop special characters
todate$Name <- gsub("\\^", "", todate$Name)
#convert the position from a character string to a factor
todate$Pos <- as.factor(todate$Pos) 
#remove the character strings infront of team abbrev
todate$Opp <- str_remove_all(todate$Opp, pattern = START %R% or("@", "v"))
#create a new column to capture Points over Salary
todate <- todate %>%
        group_by(Name) %>%
        mutate(Ppd = round(Pts/Salary,5)) %>%
        ungroup()

#create columns for Avg DFK points and Number of games captured
todate <- todate %>%
  group_by(Name) %>%
  mutate(Avg_Pts= round(mean(Pts),2), Games=n()) %>%
  ungroup()

#feature engineering avg salary column
todate <- todate %>%
  group_by(Name) %>%
  mutate(Avg_Salary = round(mean(Salary),2)) %>%
  ungroup()

#Avg Ppd - need to work on this
todate <- todate %>%
  group_by(Name) %>%
  mutate(Avg_Ppd = round(mean(Avg_Pts/Avg_Salary),4)) %>%
  ungroup()
#parse character strings from statline to separate columns using rebus
todate$Pt <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "pt") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("pt") %>%
  as.numeric()

todate$Rb <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "rb") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("rb") %>%
  as.numeric()

todate$As <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "as") %>%
  replace_na(0) %>%
  unlist()%>%
  str_remove_all("as") %>%
  as.numeric()

todate$St <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "st") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("st") %>%
  as.numeric()

todate$Bl <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "bl") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("bl") %>%
  as.numeric()

todate$To <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "to") %>%
  replace_na(0) %>%
  unlist()%>%
  str_remove_all("to") %>%
  as.numeric()

todate$Tr <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "trey") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("trey") %>%
  as.numeric()

todate$Fgm <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "-" %R% one_or_more(DGT) %R% "fg") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("-" %R% one_or_more(DGT) %R% "fg") %>%
  as.numeric()

todate$Fga <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "fg") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("fg") %>%
  as.numeric()

todate$Ftm <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "-" %R% one_or_more(DGT) %R% "ft") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("-" %R% one_or_more(DGT) %R% "ft") %>%
  as.numeric()

todate$Fta <- str_extract_all(todate$Statline, pattern = one_or_more(DGT) %R% "ft") %>%
  replace_na(0) %>%
  unlist() %>%
  str_remove_all("ft") %>%
  as.numeric()
#convert min to time object - this might need work - also want to create avg min
todate$Min <- strptime(todate$Min, format = "%M:%S")

todate$Min <- as.character(todate$Min)

todate$Min <- str_extract_all(todate$Min, pattern = one_or_more(DGT) %R% ":" %R% one_or_more(DGT) %R% ":" %R% one_or_more(DGT)) %>%
  unlist() %>%
  as.ts()
#create a vector of team abbreviations
today <- c("pho", "det", "was", "bos", "cha", "no", "okc", "ny", "orl", "hou", "bkn", "mem", "uta", "mil", "lac", "gs", "chi", "lal", "tor", "sac")

#filter for todays games
todate <- todate %>%
  filter(Team %in% today)
#avg columns
todateavg <- todate %>%
  group_by(Name) %>%
  select(Name, Avg_Pts, Avg_Salary, Avg_Ppd, Team, Opp, Pos) %>%
  ungroup()
#create dfs based on eligible position
#breakdown by position - Center eligible
center <- todateavg %>%
        filter(Pos == "C"| Pos =="PF/C") 

#breakdown by position - Forward Eligible
forward <- todateavg %>%
        filter(Pos == "PF"| Pos =="PF/C" | Pos == "SF" | Pos == "SF/PF" | Pos == "SG/SF" | Pos == "PG/SF")

#breakdown by position - Guard Eligible
guard <- todateavg %>%
        filter(Pos == "PG"| Pos =="PG/SF" | Pos == "PG/SG" | Pos == "SG" | Pos == "SG/SF")

#breakdown by position - Forward Eligible
sforward <- todateavg %>%
        filter(Pos == "SF" | Pos == "SF/PF" | Pos == "SG/SF" | Pos == "PG/SF")

#breakdown by position - Guard Eligible
sguard <- todateavg %>%
        filter( Pos == "PG/SG" | Pos == "SG" | Pos == "SG/SF")

#breakdown by position - Forward Eligible
pforward <- todateavg %>%
        filter(Pos == "PF"| Pos =="PF/C" | Pos == "SF/PF")

#breakdown by position - Guard Eligible
pguard <- todateavg %>%
        filter(Pos == "PG"| Pos =="PG/SF" | Pos == "PG/SG")
#group by position
oppavg <- todateavg %>%
  group_by(Pos,Opp) %>%
  summarize(Avg_Pts_Agst = round(mean(Avg_Pts),2)) %>%
  ungroup()

Info Viz

Whole League

#change the size of the dot based on points per game metric (dk points/salary)
todateavg %>%
      plot_ly(x=~Avg_Salary, y=~Avg_Pts, color = ~Team,
                hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Avg Points:", Avg_Pts, "<br>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers(size = ~Avg_Ppd) %>%
        layout(xaxis = list(title = "Avg DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "Avg DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Avg Salary v Avg Points") 

The graphic below represents the Average Salary v Average Points and is colored on Salary/Points ratio. The Dark to Light Spectrum is representing value with lighter being more value per dollar on average.

#Adding color as a factor for Ppd and adding axis titles
todateavg %>%
        plot_ly(x=~Avg_Salary, y=~Avg_Pts, color = ~Avg_Ppd,
                hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Points:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers() %>%
        layout(xaxis = list(title = "DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Average Salary by Points, Colored by Points per Dollar")

Faceted Chart

The graphic below is broken out by position and Average Points/Average Salary. Clicking on the team icons will add/remove any teams from the chart.

#faceted
todateavg %>%
        group_by(Pos) %>%
                do(p=plot_ly(., x= ~Avg_Salary, y= ~Avg_Pts, color = ~Team, hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Average Points:", Avg_Pts, "<br>",
                              "Average Salary:", Avg_Salary, "<br>",
                              "Team:", Team))) %>%
        subplot(nrows=5, shareY=TRUE, shareX=TRUE)

The chart below is a faceted breakdown of Average DK points versus Opponent. This will display the strengths/weaknesses of each team in regard to position.

#Average DK points Scored against Opponent by Faceted by Position - chart only changes Center for some reason
oppavg %>%
        group_by(Pos) %>%
                do(p=plot_ly(., x= ~Pos, y= ~Avg_Pts_Agst, color = ~Opp, hoverinfo = "text",
                text = ~paste("Average Points Against:", Avg_Pts_Agst, "<br>",
                              "Pos:", Pos, "<br>",
                              "Team:", Opp))) %>%
        subplot(nrows=10, shareY=FALSE, shareX=FALSE)

Charts by Position

The Charts below are all broken out by position. Size of the token represents value on an Average Points/Average Salary Ratio. Color represents team

center

#by position - center
cplotavg <- center %>%
        plot_ly(
                x = ~Avg_Salary, y = ~Avg_Pts, hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Average Pts:", Avg_Pts, "<br>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers(
                size = ~Avg_Ppd,
                color = ~Team,
                marker = list(opacity = 0.3,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "AVG DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Centers AVG")
cplotavg

DK points allowed to Center

#Opponent Points DK allowed
cplotopp <- oppavg %>%
  filter(Pos == "C") %>%
        plot_ly(
                x = ~Opp, y = ~Avg_Pts_Agst, hoverinfo = "text",
                text = ~paste("Team:", Opp, "<br>",
                              "Average Pts Against:", Avg_Pts_Agst)) %>%
        add_bars(
                color = ~Opp,
                marker = list(opacity = 0.7,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "Centers AVG")
cplotopp

power forward

#by position - power forward
pfplotavg <- pforward %>%
        plot_ly(
                x = ~Avg_Salary, y = ~Avg_Pts, hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Average Pts:", Avg_Pts, "<br>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers(
                size = ~Avg_Ppd,
                color = ~Team,
                marker = list(opacity = 0.3,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "AVG DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Power Forward AVG")
pfplotavg

DK Points allowed to Power Forward

#Opponent Points DK allowed
pfplotopp <- oppavg %>%
  filter(Pos == "PF") %>%
        plot_ly(
                x = ~Opp, y = ~Avg_Pts_Agst, hoverinfo = "text",
                text = ~paste("Team:", Opp, "<br>",
                              "Average Pts Against:", Avg_Pts_Agst)) %>%
        add_bars(
                color = ~Opp,
                marker = list(opacity = 0.7,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "Power Forward AVG")
pfplotopp

small forward

#by position - small forward
sfplotavg <- sforward %>%
        plot_ly(
                x = ~Avg_Salary, y = ~Avg_Pts, hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Average Pts:", Avg_Pts, "<br>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers(
                size = ~Avg_Ppd,
                color = ~Team,
                marker = list(opacity = 0.3,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "AVG DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Small Forward AVG")
sfplotavg

DK Points allowed to Small Forward

#Opponent Points DK allowed
Sfplotopp <- oppavg %>%
  filter(Pos == "SF") %>%
        plot_ly(
                x = ~Opp, y = ~Avg_Pts_Agst, hoverinfo = "text",
                text = ~paste("Team:", Opp, "<br>",
                              "Average Pts Against:", Avg_Pts_Agst)) %>%
        add_bars(
                color = ~Opp,
                marker = list(opacity = 0.7,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "Small Forward AVG")
Sfplotopp

All Forward eligible players

#All Forward eligible players
fplotavg <- forward %>%
        plot_ly(
                x = ~Avg_Salary, y = ~Avg_Pts, hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Average Pts:", Avg_Pts, "<br>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers(
                size = ~Avg_Ppd,
                color = ~Team,
                marker = list(opacity = 0.3,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "AVG DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Forward AVG")
fplotavg

shooting guard

#by position - shooting guard
sgplotavg <- sguard %>%
        plot_ly(
                x = ~Avg_Salary, y = ~Avg_Pts, hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Average Pts:", Avg_Pts, "<br>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers(
                size = ~Avg_Ppd,
                color = ~Team,
                marker = list(opacity = 0.3,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "AVG DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Shooting Guard AVG")
sgplotavg

DK Points Allowed to Shooting Guard

#Opponent Points DK allowed
sgplotopp <- oppavg %>%
  filter(Pos == "SG") %>%
        plot_ly(
                x = ~Opp, y = ~Avg_Pts_Agst, hoverinfo = "text",
                text = ~paste("Team:", Opp, "<br>",
                              "Average Pts Against:", Avg_Pts_Agst)) %>%
        add_bars(
                color = ~Opp,
                marker = list(opacity = 0.7,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "Shooting Guard AVG")
sgplotopp

Point guard

#by position - Point guard
pgplotavg <- pguard %>%
        plot_ly(
                x = ~Avg_Salary, y = ~Avg_Pts, hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Average Pts:", Avg_Pts, "<br>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers(
                size = ~Avg_Ppd,
                color = ~Team,
                marker = list(opacity = 0.3,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "AVG DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Point Guard AVG")
pgplotavg

DK Points Allowed to Point Guard

#Opponent Points DK allowed
pgplotopp <- oppavg %>%
  filter(Pos == "PG") %>%
        plot_ly(
                x = ~Opp, y = ~Avg_Pts_Agst, hoverinfo = "text",
                text = ~paste("Team:", Opp, "<br>",
                              "Average Pts Against:", Avg_Pts_Agst)) %>%
        add_bars(
                color = ~Opp,
                marker = list(opacity = 0.7,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "Point Guard AVG")
pgplotopp

All guard eligible players

#all guard eligible players
gplotavg <- guard %>%
        plot_ly(
                x = ~Avg_Salary, y = ~Avg_Pts, hoverinfo = "text",
                text = ~paste("Name:", Name, "<br>",
                              "Average Pts:", Avg_Pts, "<br>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Team:", Team)) %>%
        add_markers(
                size = ~Avg_Ppd,
                color = ~Team,
                marker = list(opacity = 0.3,
                              sizemode = "diameter",
                              sizeref = 2)) %>%
        layout(xaxis = list(title = "AVG DK Salary", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points", zeroline = FALSE,  showgrid=FALSE),
               title = "Guard AVG")
gplotavg