tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.48k stars 2.02k forks source link

Use `group` to dodge in `position_jitterdodge()` #5922

Closed teunbrand closed 4 months ago

teunbrand commented 4 months ago

This PR aims to fix #3656.

Briefly, instead of dodging by a set of aesthetics, it uses the innate group to dodge. Also using position = "jitterdodge" no longer fails due to missing parameters.

Some examples:

If there is no group it just jitters:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
p <- ggplot(mpg, aes("x", displ)) +
  geom_point(position = "jitterdodge")

p

If there is an explicit group, that is used to dodge:

p + aes(group = drv)

If there is an implicit automatic group, it dodges by that:

p + aes(colour = drv)

Explicit groups can be used to override implicit ones:

p + aes(group = drv, colour = factor(cyl))

Created on 2024-05-31 with reprex v2.1.0