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,84 @@
|
||||
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))
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user