Slope Chart
ggplot2: geom_segment() + geom_point() + geom_text() · Package: ggplot2 · Variables: 1 categorical + 2 numerical (start/end)
WHAT IS A SLOPE CHART?
A slope chart connects paired data points across exactly two conditions or time periods with lines, making the direction and magnitude of change immediately visible for each category. The slope (angle) of each line tells the story: upward means increase, downward means decrease, and the steepness shows how much. When lines cross, it indicates ranking changes. Slope charts are excellent for showing how multiple items changed between two points — like employee performance from Q1 to Q4, or country rankings from one year to the next. In ggplot2, combine geom_segment() with geom_point() and geom_text() for labels.
BEST FOR
- · Before/after comparison for multiple groups
- · Ranking changes between two periods
- · Period-over-period shifts
AVOID WHEN
- · More than 2 time points
- · Too many categories (lines overlap)
- · When absolute value matters more than change
R + GGPLOT2 CODE EXAMPLE
df <- data.frame(car = rownames(mtcars)[1:6],
y2020 = mtcars$mpg[1:6], y2025 = mtcars$mpg[1:6] + sample(-4:6, 6, TRUE))
ggplot(df) +
geom_segment(aes(x = 1, xend = 2, y = y2020, yend = y2025), color = "grey50") +
geom_point(aes(x = 1, y = y2020), size = 3, color = "tomato") +
geom_point(aes(x = 2, y = y2025), size = 3, color = "#ff6a00") +
scale_x_continuous(breaks = 1:2, labels = c("2020", "2025"), limits = c(0.5, 2.5)) +
labs(title = "Slope Chart: MPG Change", x = NULL, y = "MPG")Run this code now
Paste the code above into RChat and see the slope chart rendered instantly in your browser.