Best Plot Contest

Plot 1

plot1 <- team_data %>%
  plot_ly(x = ~Oreb, y = ~Pts) 

plot1

This first graph is a very simple scatterplot of points by offensive rebounds. However there is no title and it is not very clear what the data is representing.

Plot 2

plot2 <- team_data %>%
  plot_ly(x = ~Oreb, y = ~Pts, size = ~Eff, text = ~Team,
          sizes = c(1, 25), marker = list(sizemode = "diameter"),
          color = ~Team == "Milwaukee", colors = c("darkgrey", "green"))

plot2

This plot builds on the first plot by changing two aesthetic options: the points are now sized by efficieny and colored by if the team = Milwaukee (however this is not clear by the legend). Additionally, now when you hover over each point it tells you which team said point applies to.

Plot 3

# Create a new column for coloring
team_data$color_by_team <- ifelse(team_data$Team == "Milwaukee", "Milwaukee", "Other Teams")

# Convert to factor
team_data$color_by_team <- factor(team_data$color_by_team, levels = c("Other Teams", "Milwaukee"))

plot3 <- team_data %>%
  plot_ly(x = ~Oreb, y = ~Pts, size = ~Eff, text = ~Team,
          sizes = c(1, 25), marker = list(sizemode = "diameter", opacity = 1),
          color = ~color_by_team, colors = c("darkgrey", "green"), frame = ~Year) %>%
  layout(colorbar = list(title = "Team", tickvals = c(0, 1), 
                         ticktext = c("Other Teams", "Milwaukee")),
         title = "Points per Game vs. Offensive Rebounds per Game for all NBA Teams", 
                                            xaxis = list(title = "Offensive Rebounds per Game"),
                                            yaxis = list(title = "Points per Game")) 

plot3

For this plot I changed the axis/title/legend labels, the opacity of the points, and made the graph animated.

plot4 <- plot3 %>% layout(
   updatemenus = list(
     list(
       type = "buttons",
       showactive = FALSE,
       x = 0.2,  
       y = -.1,  
       buttons = list(
         
         list(
           label = "Pause",
           method = "animate",
           args = list(NULL, list(frame = list(duration = 0, 
                                               redraw = TRUE), 
                                  mode = "immediate"))
         )
       )
     )
   )
 ) 

plot4

For my final change I added a pause button so the animation can be stopped at any point.