geom_line() adds line segments connecting observations in their data order or specified grouping. It is especially useful for showing change across seasons, possession time, or another ordered variable. section 13.4 section 12.5
Use geom_line() to:
- Draw a line through summarized values, such as annual Gini coefficients or average points per possession second. section 13.4 section 8.5.1
- Combine connected observations with geom_point() to create a connected scatterplot or emphasize individual measurements. section 13.4 section 8.5.1
- Set group = 1 when the plotted observations should form one continuous line across the x-axis. section 13.4 section 8.5.1
Plot annual inequality
After calculating one Gini coefficient per season, connect the values with: ggplot(gini_summary, aes(x = season_end, y = gc, group = 1)) + geom_line(color = "coral3", size = 1.5) + geom_point(size = 3, color = "coral3"). Add geom_smooth(method = lm, se = FALSE) when a regression trend is useful. section 12.5
ggplot(ws_gini_summary, aes(x = Year, y = gc, group = 1)) +
geom_line(aes(y = gc), color = "black", size = .5) +
geom_point(size = 5, color = "seagreen3") +
geom_text(aes(label = gc),
nudge_x = 0.01, nudge_y = 0.01,
check_overlap = TRUE, size = 2.5) +
labs(title = "Gini Coefficient for Win Shares",
subtitle = "1991-2017",
x = "Season",
y = "Gini Coeffiicient",
caption = "includes a maximum top 14 win shares for each team") +
ylim(0.42, 0.60) +
theme(plot.title = element_text(hjust = 0.5, face = "bold")) +
theme(plot.subtitle = element_text(hjust = 0.5)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
annotate("rect", xmin = "1991", xmax = "2009",
ymin = 0.42, ymax = 0.60, alpha = 0.1, fill = "orange") +
annotate("rect", xmin = "2010", xmax = "2017",
ymin = 0.42, ymax = 0.60, alpha = 0.1, fill = "blue")
Inspect a complete ggplot2 example connecting annual win-share Gini coefficients, then layering points, labels, annotations, and styling. section 13.4
