ggplot2 geom_jitter() in R: Scatter With Random Jitter
The geom_jitter() function in ggplot2 adds random horizontal and vertical noise to scatter points to avoid overplotting on discrete or rounded data.
ggplot(df, aes(x, y)) + geom_jitter() ggplot(df, aes(x, y)) + geom_jitter(width = 0.2, height = 0) ggplot(df, aes(x, y)) + geom_jitter(alpha = 0.5) geom_point(position = position_jitter(width = 0.1)) # equivalent geom_point() # no jitter
Need explanation? Read on for examples and pitfalls.
What geom_jitter() does in one sentence
geom_jitter() is geom_point() with random noise added to x and y to spread overlapping points apart. Especially useful for categorical x data.
Syntax
geom_jitter(width = NULL, height = NULL, alpha = 1, ...). width and height control noise amount.
width = 0.2 or smaller for categorical x. Default jitter width is 40% of resolution, often too wide.Five common patterns
1. Categorical-numeric scatter
2. Combined with boxplot
3. Vertical-only jitter
4. With color and alpha
5. Reproducible jitter
set.seed, the plot looks slightly different each time. For reproducible reports, set the seed before plotting.geom_jitter() vs geom_point() vs position_jitter()
| Approach | Best for |
|---|---|
geom_jitter() |
Direct jitter of points |
geom_point(position = position_jitter(...)) |
More control over jitter position |
geom_point() |
No jitter (exact positions) |
A practical workflow
Pair geom_jitter with geom_boxplot to show distribution AND raw points.
Box shows summary; jittered points show raw data.
Common pitfalls
Pitfall 1: too much jitter. Default width spreads points beyond their group. Set width = 0.1 to 0.2 for cleaner display.
Pitfall 2: irreproducible plots. Without set.seed, jitter is random per run. Use set.seed() before for reports.
geom_jitter() MOVES the actual point positions. Don't use it for exact-coordinate plots like maps or precise scatters.Try it yourself
Try it: Plot mtcars cyl vs mpg with jittered points and a transparent boxplot. Save to ex_plot.
Click to reveal solution
Explanation: Boxplot for summary, jitter for raw data; outlier.shape = NA prevents double-marking.
Related ggplot2 functions
After mastering geom_jitter, look at:
geom_point(): exact positionsgeom_boxplot(): distribution summarygeom_violin(): distribution shapegeom_dotplot(): stacked dotsposition_jitter()/position_jitterdodge(): positioning helpersgeom_hex()/geom_bin2d(): heatmap for many points
FAQ
What does geom_jitter do in ggplot2?
geom_jitter() adds random horizontal and vertical noise to scatter points to spread overlapping points apart.
How do I control how much jitter?
Set width and height: geom_jitter(width = 0.2, height = 0). Default is 40% of resolution.
Should I use geom_jitter or geom_point?
geom_jitter for discrete/categorical x with overlapping points. geom_point for continuous x or when exact positions matter.
How do I make jitter reproducible?
Call set.seed(N) before the plot. Without it, jitter is random per render.
Can I combine geom_jitter with geom_boxplot?
Yes. geom_boxplot(outlier.shape = NA) + geom_jitter() shows summary AND raw data without double-marking outliers.