# install.packages(c("readr", "dplyr")) library(readr) library(dplyr) # # Load data # players <- read_csv("data/nba-players-2013-14.csv") heights <- players %>% select(Name, POS, Ht_inches) # Summary statistics summary(players$Ht_inches) # # Box plot # par(las = 1) boxplot(players$Ht_inches, main = "NBA Player Height, Inches") # # Box plot by position # # Multiple charts ppos <- unique(players$POS) players %>% distinct(POS) par(mfrow = c(1, length(ppos)), mar = c(2, 2, 2, 2), oma = c(1, 3, 2, 2), bty = "n") for (pos in ppos) { curr <- players %>% filter(POS == pos) boxplot(curr$Ht_inches, ylim = range(players$Ht_inches), main = pos) } par(mfrow = c(1, 2), las = 1) # Using the tilde notation boxplot(Ht_inches ~ POS, data = players, ylab = "", main = "NBA Player Height by Position") # Reorder players_fact <- players players_fact$POS <- factor(players_fact$POS, levels = c("C", "F/C", "F", "G/F", "G")) boxplot(Ht_inches ~ POS, data = players_fact, ylab = "", main = "NBA Player Height by Position,\nOrdered")