eclarke / ggbeeswarm

Column scatter / beeswarm-style plots in ggplot2
GNU General Public License v3.0
539 stars 31 forks source link

Odd behaviour of geom_quasirandom when colouring by a factor #83

Closed francoiskroll closed 1 year ago

francoiskroll commented 1 year ago

Thanks for an amazingly useful package!

I am having an odd issue (maybe caused by a recent update?), which I have just posted on StackOverflow:

https://stackoverflow.com/questions/76034230/r-ggplot2-odd-behaviour-of-geom-quasirandom-when-colouring-by-a-factor

Am I doing something stupid?


Edit: adding group=1 solves this issue (thanks stefan on StackOverflow), like:

ggplot(mtcars, aes(x=factor(gear), y=drat, group=1, color=factor(cyl))) +
  geom_quasirandom()

But I did not have to do this previously, so maybe this is not the expected behaviour regardless?

csdaw commented 1 year ago

Thanks, this seems to be a bug introduced in a recent update, as it works as you describe in v0.6.0 (see below).

I believe the intended behaviour should be the points don't move when coloured, unless position = position_dodge() is specified.

I'll look into it.

library(ggbeeswarm)
#> Loading required package: ggplot2

packageVersion("ggbeeswarm")
#> [1] '0.6.0'

## Quasirandom
# this is correctly placing the dots:
ggplot(mtcars, aes(x=factor(gear), y=drat)) +
  geom_quasirandom()


# still correct
ggplot(mtcars, aes(x=factor(gear), y=drat, color=factor(cyl))) +
  geom_quasirandom()

Created on 2023-04-22 with reprex v2.0.2