geom_histogram() adds a histogram for one continuous variable. It divides the x-axis into bins, counts observations in each bin, and displays the resulting frequency distribution. section 2.5.3
NBA career win shares
Map WS to x in ggplot(), then add geom_histogram(fill = "royalblue3", color = "royalblue3", bins = 8). Add labs() for titles and axis labels, and print the plot. The resulting histogram shows that career win shares are right-skewed: many first-round picks recorded few win shares, while a small number recorded many. section 2.5.3
p1 <- ggplot(draft, aes(x = WS)) +
geom_histogram(fill = "royalblue3", color = "royalblue3",
bins = 8) +
labs(title = "Career Win Shares Distribution of
NBA First-Round Selections",
subtitle = "2000-09 NBA Drafts",
x = "Career Win Shares",
y = "Frequency") +
theme(plot.title = element_text(face = "bold"))
print(p1)
View a complete ggplot2 histogram combining data mapping, bin count, fill and border colors, labels, theme styling, and output. section 2.5.3
