ggplot2 geom_pointrange() in R: Point With Range Bar
The geom_pointrange() function in ggplot2 draws a central POINT with a vertical RANGE bar from ymin to ymax. It is a cleaner-looking alternative to geom_errorbar() for showing point estimates with uncertainty.
ggplot(df, aes(x, y, ymin = lo, ymax = hi)) + geom_pointrange() geom_pointrange(size = 1) # larger point + thicker bar geom_pointrange(fatten = 2) # control point size relative to bar geom_errorbar() # bar with whiskers (different style)
Need explanation? Read on for examples and pitfalls.
What geom_pointrange() does in one sentence
geom_pointrange() draws a point at (x, y) with a vertical line from ymin to ymax showing the range. It combines geom_point() and geom_linerange() into one geom.
Syntax
geom_pointrange(mapping = NULL, data = NULL, fatten = 4, size = 0.5, ...). Requires aes(x, y, ymin, ymax).
Five common patterns
1. Per-group summary
2. Forest plot
For horizontal pointrange, use ggstance::geom_pointrangeh.
3. With color and dodge
4. Custom point size
5. Stat_summary alternative
geom_pointrange is geom_point + geom_linerange combined. Cleaner visual than geom_errorbar (which adds whisker caps).geom_pointrange() vs geom_errorbar() vs geom_linerange()
| Function | Components |
|---|---|
geom_pointrange() |
Point + line from ymin to ymax |
geom_errorbar() |
Vertical line with horizontal whiskers |
geom_linerange() |
Line only (no point) |
geom_crossbar() |
Box (median + range) |
When to use which:
- pointrange for clean point-estimate summaries.
- errorbar for traditional bar-chart-style error.
- linerange when overlaid on points.
- crossbar for median-style summaries.
A practical workflow
Use geom_pointrange to compactly summarize estimates with their uncertainty, especially in forest plots.
Coefficient plot with CIs.
Common pitfalls
Pitfall 1: position_dodge needs same dodge for both point and range. Pass to the geom: geom_pointrange(position = position_dodge(0.5)).
Pitfall 2: forgetting ymin/ymax. Both required; missing errors.
geom_pointrange() doesn't have horizontal whiskers like geom_errorbar. Some readers expect the whiskered look; pick by visual preference.Try it yourself
Try it: Plot mean mpg per cyl with +/- 1 standard deviation as point + range. Save to ex_plot.
Click to reveal solution
Explanation: Compute mean and SD per cyl; pointrange shows mean as point with +/- SD as range.
Related ggplot2 functions
After mastering geom_pointrange, look at:
geom_errorbar(): bar with whiskersgeom_linerange(): line without pointgeom_crossbar(): box-style summarystat_summary(): compute summary on the flymean_se(),mean_cl_normal(): stat data helpers
FAQ
What does geom_pointrange do in ggplot2?
geom_pointrange() draws a central point with a vertical line from ymin to ymax. Used for point-estimate-with-uncertainty plots.
What is the difference between geom_pointrange and geom_errorbar?
pointrange has a central point + line. errorbar has only the line + horizontal whiskers at ends. Cleaner visual with pointrange.
How do I make horizontal point ranges?
Use ggstance::geom_pointrangeh (different package), or swap aes: aes(y, x, xmin = lo, xmax = hi) with coord_flip.
How do I control point size?
Use fatten: geom_pointrange(fatten = 8). Higher = larger point relative to line width.
Can I dodge multiple groups?
Yes. Pass position = position_dodge(0.5). Same as geom_errorbar.