Skip to content

geom_jitter fails when coordinate values have very small spread #6562

@nicholasdavies

Description

@nicholasdavies

When geom_jitter is given some data where the y coordinates are all the same, a default jitter height is chosen. But if the y coordinates differ only by a small magnitude, the selection of the jitter height seems to fail and nothing is plotted.

Minimal working example:

library(ggplot2)

set.seed(123)
ggplot(data.frame(x = 1:50, y = 0)) +
    geom_jitter(aes(x, y))

set.seed(123)
ggplot(data.frame(x = 1:50, y = 1e-8 * rnorm(50))) +
    geom_jitter(aes(x, y))
#> Warning in min(d[d > tolerance]): no non-missing arguments to min; returning
#> Inf
#> Warning in stats::runif(length(x), -amount, amount): NAs produced
#> Warning: Removed 50 rows containing missing values or values outside the scale range
#> (`geom_point()`).

Created on 2025-07-25 with reprex v2.1.1

I would have expected both plots to be more or less the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions