85 lines
2.0 KiB
R
85 lines
2.0 KiB
R
library(readr)
|
|
library(dplyr)
|
|
|
|
|
|
#
|
|
# Load data
|
|
#
|
|
|
|
players <- read_csv("data/nba-players-2013-14.csv")
|
|
head(players)
|
|
|
|
|
|
#
|
|
# Player heights distributions
|
|
#
|
|
|
|
warriors <- players %>%
|
|
filter(Team == "Warriors") %>%
|
|
arrange(-Ht_inches)
|
|
|
|
# Bar chart
|
|
par(mar=c(5,10,5,5))
|
|
barplot(warriors$Ht_inches,
|
|
names.arg=warriors$Name,
|
|
horiz=TRUE,
|
|
border=NA, las=1,
|
|
main="Heights of Golden State Warriors, 2013-14")
|
|
|
|
|
|
# Dots on a continuous height scale
|
|
htrange <- range(warriors$Ht_inches)
|
|
cnts <- rep(0, htrange[2]-htrange[1]+1)
|
|
y <- c()
|
|
for (i in 1:dim(warriors)[1]) {
|
|
cntindex <- warriors$Ht_inches[i] - htrange[1] + 1
|
|
cnts[cntindex] <- cnts[cntindex] + 1
|
|
y <- c(y, cnts[cntindex])
|
|
}
|
|
plot(warriors$Ht_inches, y,
|
|
xlim = c(69, 87),
|
|
ylim = c(0, 10),
|
|
type="n",
|
|
main="Player heights", xlab="inches", ylab="count")
|
|
points(warriors$Ht_inches, y, pch=21, col=NA, bg="#999999")
|
|
|
|
|
|
# Dots for all players
|
|
htrange <- range(players$Ht_inches)
|
|
cnts <- rep(0, htrange[2]-htrange[1]+1)
|
|
y <- c()
|
|
for (i in 1:dim(players)[1]) {
|
|
cntindex <- players$Ht_inches[i] - htrange[1] + 1
|
|
cnts[cntindex] <- cnts[cntindex] + 1
|
|
y <- c(y, cnts[cntindex])
|
|
}
|
|
|
|
par(las=1)
|
|
plot(players$Ht_inches, y,
|
|
xlim = htrange,
|
|
ylim = c(0, max(cnts)),
|
|
type="n",
|
|
main="Player heights", xlab="inches", ylab="count")
|
|
points(players$Ht_inches, y, pch=21, col=NA, bg="#999999")
|
|
|
|
# Bar chart version of counts
|
|
barplot(cnts, names.arg=69:87,
|
|
main="Player heights",
|
|
xlab="inches", ylab="count", border=NA, las=1)
|
|
|
|
|
|
# Histogram
|
|
hist(players$Ht_inches,
|
|
breaks=seq(65, 90, 1),
|
|
xlab="inches",
|
|
main="NBA Player Heights")
|
|
|
|
# Vary bin sizes
|
|
par(mfrow=c(1,3), mar=c(3,3,3,3))
|
|
hist(players$Ht_inches, main="NBA Player Heights", xlab="inches", breaks=seq(65, 90, 1))
|
|
hist(players$Ht_inches, main="NBA Player Heights", xlab="inches", breaks=seq(65, 90, 2))
|
|
hist(players$Ht_inches, main="NBA Player Heights", xlab="inches", breaks=seq(65, 90, 5))
|
|
|
|
|
|
|