date()
## [1] "Sun Nov 5 20:52:46 2017"
nfl_stats <- data.frame(
team = c("Saints","Falcons","Redskins","Patriots","Cowboys",
"Raiders","Steelers","Packers","Cardinals","Colts",
"Titans","Seahawks","Bengals","Chargers","Bears",
"Bills",'Ravens',"Bucs","Panthers","Chiefs",
"Lions","Eagles","Jags","Dolphins","Giants",
"Jets","Broncos","Vikings","Texans","Browns",
"49ners","Rams"),
o_ydspergame = c(426.0,415.8,403.4,386.3,376.7,
373.3,372.6,368.8,366.8,364.4,
358.0,357.2,356.9,356.8,356.5,
354.1,347.7,346.4,343.7,343.0,
338.8,337.4,334.9,334.9,330.7,
329.3,323.1,315.1,314.7,311.0,
308.1,262.7),
o_ptspergame = c(29.3,33.8,24.8,27.6,26.3,
26.0,24.9,27.0,26.1,25.7,
23.8,22.1,20.3,25.6,17.4,
24.9,21.4,22.1,23.1,24.3,
21.6,22.9,19.9,22.7,19.4,
17.2,20.8,20.4,17.4,16.5,
19.3,14.0),
d_ydspergame = c(375.4,371.2,377.9,326.4,343.9,
375.1,342.6,363.9,305.2,382.9,
357.5,318.7,350.8,347.1,346.8,
357.0,322.1,367.9,359.8,368.5,
354.8,342.8,321.7,382.6,339.7,
342.4,316.1,314.9,301.3,392.4,
406.4,337.0),
d_ptspergame = c(28.4,25.4,23.9,15.6,19.1,
24.1,20.4,24.3,22.6,24.5,
23.6,18.3,19.7,26.4,24.9,
23.6,20.1,23.1,25.1,19.4,
22.4,20.7,25.0,23.8,17.8,
25.6,18.6,19.2,20.5,28.3,
30.0,24.6),
wins = c(7,11,8,14,13,
12,11,10,7,8,
7,10,6,5,3,
7,8,9,6,12,
9,7,3,10,11,
5,9,8,9,1,
2,4),
loss = c(9,5,7,2,3,
4,5,6,8,8,
9,5,9,11,13,
9,8,7,10,4,
7,9,13,6,5,
11,7,8,7,15,
14,12),
playoffs = c("no","yes","no","yes","yes",
"yes","yes","yes","no","no",
"no","yes","no","no","no",
"no","no","no","no","yes",
"yes","no","no","yes","yes",
"no","no","no","yes","no",
"no","no")
)
nfl_stats$ptsdiff <- nfl_stats$o_ptspergame- nfl_stats$d_ptspergame
nfl_stats$ydsdiff <- nfl_stats$o_ydspergame- nfl_stats$d_ydspergame
nfl_stats$wlratio <- nfl_stats$wins/nfl_stats$loss
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
plot_ly(data = nfl_stats, x = nfl_stats$ptsdiff, y = nfl_stats$wlratio, mode = "markers", color = nfl_stats$playoffs, colors = c('red','green'), text = nfl_stats$team) %>%
add_markers()%>%
add_text(textposition = 'bottom', textfont = list(family = 'sans serif', size = 8, color = 'black')) %>%
layout(showlegend = FALSE) %>%
layout(title = 'NFL points diff by win ratio',
xaxis = list(title ='Points Differential'),
yaxis = list(title ='Win/Loss Ratio'),
legend = list(title = 'Playoffs',yanchor = 'top'))