33 lines
454 B
R
33 lines
454 B
R
library(readr)
|
|
library(dplyr)
|
|
|
|
|
|
#
|
|
# Load data
|
|
#
|
|
|
|
players <- read_csv("data/nba-players-2013-14.csv")
|
|
|
|
|
|
#
|
|
# Density plot
|
|
#
|
|
|
|
# Calculate density coordinates
|
|
pdens <- density(players$Ht_inches)
|
|
|
|
# Plot
|
|
par(las = 1)
|
|
plot(pdens, lwd = 2,
|
|
main = "NBA Player Height")
|
|
polygon(pdens,
|
|
col = "lightblue")
|
|
|
|
# Max point
|
|
i <- which.max(pdens$y)
|
|
abline(v = pdens$x[i],
|
|
lty = 2)
|
|
points(pdens$x[i], pdens$y[i],
|
|
pch = 21,
|
|
bg = "black")
|