-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadData.R
44 lines (34 loc) · 2.2 KB
/
loadData.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
title_with_subtitle <- function(title, subtitle = "") {
ggtitle(bquote(atop(.(title), atop(.(subtitle)))))
}
#raw shot data
shot.1415 <<- read.csv('data/2014-2015shot.csv', header = TRUE, stringsAsFactors = FALSE)
shot.1516 <<- read.csv('data/2015-2016shot.csv', header = TRUE, stringsAsFactors = FALSE)
#league average
league.1415 <<- shotAnalysis(shot.1415)
league.1516 <<- shotAnalysis(shot.1516)
#player value
value.1415 <<- read.csv('data/2014-2015playervalue.csv', header = TRUE, stringsAsFactors = FALSE)
value.1516 <<- read.csv('data/2015-2016playervalue.csv', header = TRUE, stringsAsFactors = FALSE)
#value plot
value.plot.1516 <<- ggplot() +
geom_point(aes(x = value.1516$FGA, y = value.1516$PtsDiff, color = factor(sign(value.1516$PtsDiff))), size = 4, shape = 1) +
scale_colour_manual(values=c("#D55E00", "#009E73"))+
ylab('Value Added by Points Scored') + xlab('FG Attempt') +
title_with_subtitle('Player Scoring Performance 2015-2016 NBA', 'as of 01/03/2016') +
theme_bw(base_size = 15) + theme(legend.position = 'none')
value.plot.1415 <<- ggplot() +
geom_point(aes(x = value.1415$FGA, y = value.1415$PtsDiff, color = factor(sign(value.1415$PtsDiff))), size = 4, shape = 1) +
scale_colour_manual(values=c("#D55E00", "#009E73"))+
ylab('Value Added by Points Scored') + xlab('FG Attempt') +
title_with_subtitle('Player Scoring Performance 2014-2015 NBA', 'Regular Season') +
theme_bw(base_size = 15) + theme(legend.position = 'none')
#shot selection
shotSel.dist.1415 <- aggregate(totalFGA ~ ShotDist, league.1415, sum)[c(1, 8, 2:7),]
shotSel.dist.1415 <<- mutate(shotSel.dist.1415, perc = totalFGA/sum(totalFGA), y.breaks = cumsum(perc) - perc/2)
shotSel.def.1415 <- aggregate(totalFGA ~ DefDist, league.1415, sum)
shotSel.def.1415 <<- mutate(shotSel.def.1415, perc = totalFGA/sum(totalFGA), y.breaks = cumsum(perc) - perc/2)
shotSel.dist.1516 <- aggregate(totalFGA ~ ShotDist, league.1516, sum)[c(1, 8, 2:7),]
shotSel.dist.1516 <<- mutate(shotSel.dist.1516, perc = totalFGA/sum(totalFGA), y.breaks = cumsum(perc) - perc/2)
shotSel.def.1516 <- aggregate(totalFGA ~ DefDist, league.1516, sum)
shotSel.def.1516 <<- mutate(shotSel.def.1516, perc = totalFGA/sum(totalFGA), y.breaks = cumsum(perc) - perc/2)