R
ggplot2
pointrange
data visualization
R programming

ggplot2 geom_pointrange example in R

Codemia Knowledge Hub ·

geom_pointrange draws a point for a central estimate and a line for its lower and upper bounds. Map y, ymin and ymax in aes(). It suits means with confidence intervals, model coefficients with standard errors, or any estimate paired with uncertainty.

A basic point-range plot

r
1library(ggplot2)
2
3results <- data.frame(
4  group = c("A", "B", "C"),
5  mean = c(10.2, 12.8, 9.7),
6  lower = c(9.4, 11.6, 8.9),
7  upper = c(11.0, 14.0, 10.5)
8)
9
10ggplot(results, aes(x = group, y = mean, ymin = lower, ymax = upper)) +
11  geom_pointrange()

Each group gets a point at mean and a vertical line from lower to upper, so the viewer sees the uncertainty at a glance.

Styling the points and lines

Color, point size, and line thickness make the plot easier to read:

r
1ggplot(results, aes(x = group, y = mean, ymin = lower, ymax = upper)) +
2  geom_pointrange(
3    color = "steelblue",
4    fatten = 3,
5    linewidth = 0.7
6  ) +
7  labs(
8    title = "Estimated mean and interval by group",
9    x = "Group",
10    y = "Value"
11  ) +
12  theme_minimal()

fatten sets the size of the point relative to the line, which makes the center estimate stand out without hiding the interval.

Several series per category with position_dodge

Dodge the series so their ranges do not overlap:

r
1results2 <- data.frame(
2  group = rep(c("A", "B", "C"), each = 2),
3  model = rep(c("Baseline", "New"), times = 3),
4  mean = c(10.2, 11.1, 12.8, 13.5, 9.7, 10.4),
5  lower = c(9.4, 10.3, 11.6, 12.7, 8.9, 9.6),
6  upper = c(11.0, 11.9, 14.0, 14.3, 10.5, 11.2)
7)
8
9ggplot(results2, aes(x = group, y = mean, ymin = lower, ymax = upper, color = model)) +
10  geom_pointrange(
11    position = position_dodge(width = 0.4)
12  ) +
13  theme_minimal()

This works well for comparing experimental conditions or model variants side by side.

Summaries, not raw distributions

A point-range plot summarizes the data; it does not show every observation. To show the actual distribution, add points, violin plots, or boxplots. For reports and model output, the summary is usually what readers need.

Mistakes to avoid

  • Passing raw observations: the geom expects one point and one interval per row. Summarize raw measurements first or use a different statistic layer.
  • Unlabeled intervals: readers cannot tell whether the range is a confidence interval, a standard deviation, or a min-to-max span unless the title, caption, or text says so.
  • Overlap: dense categories or shared x positions get messy. Dodge, flip coordinates, or simplify the comparison.
  • Axis scales: an axis that starts far from zero or is transformed can make small differences look large. That can be fine, but make it a deliberate choice.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design