Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
MLS offseason turnover data, 2013 - 2015
data <- read.csv("turnover.csv")
summary(data)
str(data)
# Histograms
# Figure 1 - histogram of turnover by player
summary(data$Pctg.Players)
hist(
data$Pctg.Players,
xlim=c(0,1),
col="grey",
xlab="Percentage of players departing",
main="Fig 1. Histogram of roster turnover, counting by player"
)
grid()
# Figure 2 - histogram of turnover by playing time
summary(data$Pctg.Minutes)
hist(
data$Pctg.Minutes,
xlim=c(0,1),
col="grey",
xlab="Percentage of Minutes departing",
main="Fig 2. Histogram of roster turnover, counting by playing time"
)
grid()
# Scatterplot
plot(
data$Pctg.Players, data$Pctg.Minutes,
pch=19,
las=1,
col="black",
xlim=c(0,1),
ylim=c(0,1),
main="Fig 3. Scatterplot of roster turnover",
xlab="Percentage of players departing",
ylab="Percentage of minutes departing"
)
grid()
# Tunover by team
plot(
data$Team3,
data$Pctg.Players,
col="gray",
las=1,
ylim=c(0.2,0.7),
main="Roster turnover by MLS team, measured by players",
ylab="Percentage of players departing"
)
grid()
plot(
data$Team3,
data$Pctg.Minutes,
col="gray",
las=1,
ylim=c(0.1,0.6),
main="Fig 4. Roster turnover by MLS team, measured by playing time",
ylab="Percentage of minutes departing"
)
grid()
# Comparing turnover to PPG earned
plot(
data$PPG,
data$Pctg.Minutes,
col="black",
las=1,
pch=19,
main="Fig 5. Roster turnover by minutes, compared to Points Per Game",
xlab="Points per game",
ylab="Roster turnover by minutes played"
)
grid()
# Modeling turnover based on team success
model <- lm(data$Pctg.Minutes ~ data$PPG)
summary(model)
# Individual team plots
par(mfrow=c(1,2))
plotTurnover("Chicago", colors.chi)
plotSuccess("Chicago", colors.chi)
plotTurnover("Columbus", colors.clb)
plotSuccess("Columbus", colors.clb)
plotTurnover("Colorado", colors.col)
plotSuccess("Colorado", colors.col)
plotTurnover("Dallas", colors.dal)
plotSuccess("Dallas", colors.dal)
plotTurnover("DC", colors.dc)
plotSuccess("DC", colors.dc)
plotTurnover("Houston", colors.hou)
plotSuccess("Houston", colors.hou)
plotTurnover("Kansas City", colors.kc)
plotSuccess("Kansas City", colors.kc)
plotTurnover("Los Angeles", colors.la)
plotSuccess("Los Angeles", colors.la)
plotTurnover("Montreal", colors.mtl)
plotSuccess("Montreal", colors.mtl)
plotTurnover("New England", colors.ne)
plotSuccess("New England", colors.ne)
plotTurnover("New York", colors.ny)
plotSuccess("New York", colors.ny)
# plotTurnover("New York City", colors.nyc)
# plotSuccess("New York City", colors.nyc)
# plotTurnover("Orlando", colors.orl)
# plotSuccess("Orlando", colors.orl)
plotTurnover("Philadelphia", colors.phi)
plotSuccess("Philadelphia", colors.phi)
plotTurnover("Portland", colors.por)
plotSuccess("Portland", colors.por)
plotTurnover("Real Salt Lake", colors.rsl)
plotSuccess("Real Salt Lake", colors.rsl)
plotTurnover("Seattle", colors.sea)
plotSuccess("Seattle", colors.sea)
plotTurnover("San Jose", colors.sj)
plotSuccess("San Jose", colors.sj)
plotTurnover("Toronto", colors.tor)
plotSuccess("Toronto", colors.tor)
plotTurnover("Vancouver", colors.van)
plotSuccess("Vancouver", colors.van)
plotTurnover <- function(team, color) {
# Start new plot
par(new=F)
# Background dots are the entire league since 2013
plot(
data$Pctg.Players,
data$Pctg.Minutes,
pch=19,
col="#dddddd",
xlim=c(0.2,0.8),
ylim=c(0.1,0.6),
main="",
xlab="% Players departing",
ylab="% Minutes departing",
las=1
)
# Next we draw the grid
grid(col="#eeeeee")
# Next we overlay a new dataset
par(new=T)
# Foreground dots are the team
plot(
data$Pctg.Players[data$Team==team],
data$Pctg.Minutes[data$Team==team],
pch=21,
bg=color,
col="black",
xlim=c(0.2,0.8),
ylim=c(0.1,0.6),
main=paste(team, " Turnover"),
xlab="",
ylab="",
las=1
)
}
plotSuccess <- function(team, color) {
# Start new plot
par(new=F)
# Background dots are the entire league since 2013
plot(
data$PPG,
data$Pctg.Minutes,
pch=19,
col="#dddddd",
xlim=c(0.5,1.9),
ylim=c(0.1,0.6),
main="",
xlab="Points Per Game",
ylab="% Minutes departing",
las=1
)
# Next we draw the grid
grid(col="#eeeeee")
# Next we overlay a new dataset
par(new=T)
# Foreground dots are the team
plot(
data$PPG[data$Team==team],
data$Pctg.Minutes[data$Team==team],
pch=21,
bg=color,
col="black",
xlim=c(0.5,1.9),
ylim=c(0.1,0.6),
main="Turnover by Success",
xlab="",
ylab="",
las=1
)
}
Team Team3 Season Pctg.Players Pctg.Minutes Players Minutes Playoffs Position PPG
Chicago CHI 2013 0.52 0.35 14 11619 No 6 1.44
Chicago CHI 2014 0.59 0.34 17 11329 No 9 1.06
Chicago CHI 2015 0.7 0.58 21 19415 No 10 0.88
Chivas USA CHV 2013 0.71 0.58 24 19327 No 9 0.76
Colorado COL 2013 0.52 0.27 16 9203 Yes 5 1.5
Colorado COL 2014 0.52 0.34 15 11373 No 8 0.94
Colorado COL 2015 0.57 0.57 17 19328 No 10 1.09
Columbus CLB 2013 0.36 0.33 9 11012 No 8 1.21
Columbus CLB 2014 0.44 0.26 12 8580 Yes 3 1.53
Columbus CLB 2015 0.36 0.13 9 4495 Yes 2 1.56
Dallas DAL 2013 0.4 0.31 10 10459 No 8 1.29
Dallas DAL 2014 0.38 0.28 10 9422 Yes 4 1.59
Dallas DAL 2015 0.42 0.28 10 9313 Yes 1 1.76
DC DC 2013 0.62 0.49 21 16540 No 10 0.47
DC DC 2014 0.38 0.19 10 6251 Yes 1 1.74
DC DC 2015 0.42 0.36 10 12224 Yes 4 1.5
Houston HOU 2013 0.32 0.18 8 6073 Yes 4 1.5
Houston HOU 2014 0.46 0.31 11 10255 No 8 1.15
Houston HOU 2015 0.42 0.31 11 10493 No 8 1.24
Kansas City KC 2013 0.24 0.17 6 5598 Yes 2 1.71
Kansas City KC 2014 0.53 0.44 16 14600 Yes 5 1.44
Kansas City KC 2015 0.36 0.21 10 7096 Yes 6 1.5
Los Angeles LA 2013 0.41 0.29 11 9707 Yes 3 1.56
Los Angeles LA 2014 0.31 0.2 9 6719 Yes 2 1.79
Los Angeles LA 2015 0.45 0.41 13 13842 Yes 5 1.5
Montreal MTL 2013 0.24 0.17 6 5855 Yes 5 1.44
Montreal MTL 2014 0.56 0.47 18 15833 No 10 0.82
Montreal MTL 2015 0.37 0.25 11 8409 Yes 3 1.5
New England NE 2013 0.31 0.16 8 5393 Yes 3 1.5
New England NE 2014 0.35 0.14 9 4827 Yes 2 1.62
New England NE 2015 0.24 0.13 5 4415 Yes 5 1.47
New York NY 2013 0.33 0.28 9 9448 Yes 1 1.74
New York NY 2014 0.63 0.55 17 18368 Yes 4 1.47
New York NY 2015 0.25 0.1 6 3397 Yes 1 1.76
New York City NYC 2015 0.5 0.42 15 13917 No 8 1.09
Orlando ORL 2015 0.43 0.29 13 9503 No 7 1.29
Philadelphia PHI 2013 0.42 0.23 10 7754 No 7 1.35
Philadelphia PHI 2014 0.38 0.31 11 10324 No 6 1.24
Philadelphia PHI 2015 0.57 0.46 16 15339 No 9 1.09
Portland POR 2013 0.37 0.18 10 6130 Yes 1 1.68
Portland POR 2014 0.4 0.32 10 10767 No 6 1.44
Portland POR 2015 0.48 0.28 11 9334 Yes 3 1.56
Real Salt Lake RSL 2013 0.22 0.12 6 4101 Yes 2 1.65
Real Salt Lake RSL 2014 0.32 0.32 8 10655 Yes 3 1.65
Real Salt Lake RSL 2015 0.3 0.22 8 7208 No 9 1.21
San Jose SJ 2013 0.46 0.34 13 11485 No 6 1.5
San Jose SJ 2014 0.44 0.4 12 13466 No 9 0.88
San Jose SJ 2015 0.38 0.13 10 4222 No 7 1.38
Seattle SEA 2013 0.59 0.45 17 14921 Yes 4 1.53
Seattle SEA 2014 0.33 0.17 8 5766 Yes 1 1.88
Seattle SEA 2015 0.45 0.36 13 11959 Yes 4 1.5
Toronto TOR 2013 0.69 0.54 24 18195 No 9 0.85
Toronto TOR 2014 0.48 0.4 13 13456 No 7 1.21
Toronto TOR 2015 0.44 0.31 12 10510 Yes 6 1.44
Vancouver VAN 2013 0.46 0.45 12 15118 No 7 1.41
Vancouver VAN 2014 0.35 0.27 9 9093 Yes 5 1.47
Vancouver VAN 2015 0.31 0.22 8 7465 Yes 2 1.56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment