Skip to content

Misleading noise when using geom_jitter in combination with facet_wrap #3722

@hkosm

Description

@hkosm

Hello,

I like to use geom_jitter mostly to plot discrete data and avoid overplotting.

When using a combination of geom_jitter and facet_wrap with free scales I came to the issue that due to the free scales, jittering appeared misleading.

In the example below, I would like to see approximately equal noise, as I use jittering purely for visibility of data points. Apparently though, due to the free scales in geom_wrap the jittering looks different in the two facets.
How could this be approached? Could this be an issue inside face_wrap?

library(ggplot2)

set.seed(123)
df <- data.frame(
  y = rnorm(100, 50, 10),
  x = c(rep(1:5, 10), rep(seq(0, 100, length.out = 5), 10)),
  group = c(rep("a", times = 50), rep("b", times = 50))
)

ggplot(df, aes(x = x, y = y)) +
  geom_point(color = "orange", alpha = 0.7) +
  geom_point(position = "jitter", color = "blue", alpha = 0.7) +
  facet_wrap( ~ group, scales = "free")

Created on 2020-01-10 by the reprex package (v0.3.0)

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