Add VT2-examples: all 6 chapters of 'Visualize This' (110 files) — data scraping, ETL, trends, categorical, multivariate, spatial, distribution analysis
This commit is contained in:
1 parent
088771a9cf
commit
b42b866a8c
110 files changed
+400895
No files matched your search
@@ -0,0 +1,70 @@
|
||||
library(readr)
|
||||
library(dplyr)
|
||||
|
||||
|
||||
#
|
||||
# Load data
|
||||
#
|
||||
|
||||
players <- read_csv("data/nba-players-2013-14.csv")
|
||||
|
||||
|
||||
#
|
||||
# Histogram
|
||||
#
|
||||
|
||||
# Default histogram
|
||||
par(las = 1)
|
||||
hist(players$Ht_inches,
|
||||
xlab="inches",
|
||||
main="NBA Player Heights")
|
||||
|
||||
|
||||
# Smaller breaks
|
||||
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(5,3,3,3))
|
||||
hist(players$Ht_inches,
|
||||
breaks=seq(65, 90, 1),
|
||||
xlab="inches", main="One-inch bins")
|
||||
hist(players$Ht_inches,
|
||||
breaks=seq(65, 90, 3),
|
||||
xlab="inches", main="Three-inch bins")
|
||||
hist(players$Ht_inches,
|
||||
breaks=seq(65, 90, 6),
|
||||
xlab="inches", main="Six-inch bins")
|
||||
|
||||
|
||||
#
|
||||
# Comparison between positions
|
||||
#
|
||||
|
||||
ppos <- unique(players$POS)
|
||||
par(mfrow=c(5,1), mar=c(2,3,3,2), oma=c(2,2,2,2))
|
||||
for (pos in ppos) {
|
||||
curr <- players %>% filter(POS == pos)
|
||||
hist(curr$Ht_inches,
|
||||
breaks=seq(65, 90, 1),
|
||||
xlab="inches", main=paste0(pos, " Heights"))
|
||||
}
|
||||
|
||||
|
||||
ppos2 <- c("G", "G/F", "F", "F/C", "C")
|
||||
par(mfrow=c(5,1))
|
||||
for (pos in ppos2) {
|
||||
curr <- players %>% filter(POS == pos)
|
||||
curr_mean <- mean(curr$Ht_inches)
|
||||
|
||||
hist(curr$Ht_inches,
|
||||
breaks=seq(65, 90, 1),
|
||||
border = "white",
|
||||
xlab="inches",
|
||||
main=paste0(pos, " Heights"))
|
||||
abline(v = curr_mean,
|
||||
col = "blue",
|
||||
lwd = 2)
|
||||
}
|
||||
Reference in new issue
Block a user