#create a vector of team abbreviations
today <- c("orl", "bos", "ny", "cle", "dal", "mil", "mem", "min", "chi", "okc", "atl", "uta", "no", "lal", "lac", "sac")

#filter for todays games
todate <- todate %>%
  filter(Team %in% today)
oppavg <- oppavg %>%
  filter(Opp %in% today)

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>",
                              "Avg Salary:", Avg_Salary, "<br>",
                              "Avg Pts", Avg_Pts, "<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)

The chart below represents a stacked view providing some insights into what teams give up to position.

#stacking by team 
oppavg %>%
  plot_ly(x=~Opp, y=~Avg_Pts_Agst, color = ~Pos) %>%
  add_bars() %>%
  layout(barmode = "stack")

Below is a boxplot representing Points against Opponent across all positions.

#Box Plot
todate %>%
  plot_ly(x=~Opp, y=~Pts) %>%
  add_boxplot()

The following boxplot represents Points scored by Position

#Box Plot
todate %>%
  plot_ly(x=~Pos, y=~Pts, color = ~Pos) %>%
  add_boxplot()

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

Defense Points Allowed by Position

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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "Centers AVG")
cplotopp

DK points allowed to PF/C

#Opponent Points DK allowed
pfcplotopp <- oppavg %>%
  filter(Pos == "PF/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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "PF/C AVG")
pfcplotopp

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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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

DK Points allowed to PF/SF

#Opponent Points DK allowed
pfsfplotopp <- oppavg %>%
  filter(Pos == "SF/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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "PF/SF AVG")
pfsfplotopp

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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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

DK Points allowed to SF/SG

#Opponent Points DK allowed
sgsfplotopp <- oppavg %>%
  filter(Pos == "SG/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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "SG/SF AVG")
sgsfplotopp

DK Points allowed to SF/PG

#Opponent Points DK allowed
pgsfplotopp <- oppavg %>%
  filter(Pos == "PG/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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "PG/SF AVG")
pgsfplotopp

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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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

DK Points Allowed to PG/SG

#Opponent Points DK allowed
pgsgplotopp <- 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.6,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        layout(xaxis = list(title = "Team", zeroline = FALSE, showgrid=FALSE),
                yaxis = list(title = "AVG DK Points Against", zeroline = FALSE,  showgrid=FALSE),
               title = "PG/SG AVG")
pgsgplotopp

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

###Offense DK Points Scored by Pos

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.1,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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

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.1,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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

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.1,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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

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.1,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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.1,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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

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.1,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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

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.1,
                              sizemode = "diameter",
                              sizeref = 2.5)) %>%
        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