0

I'm having difficulty getting geom_jitter to separate my data points by a third variable (phase).

I'd like for each bar in this 2x2 graph to have its own set of jittered data points for each phase condition.

Right now the points are grouped between the two phase bars (sorry couldn't upload the image -- don't have my 10 posts yet).

I know I'm missing something in the geom_jitter aes, but not sure what it is -- fill=phase is not doing the trick.

ggplot(datalong, aes(grp, score)) +
  geom_bar(stat = "summary", fun.y = "mean", aes(fill=phase), position = "dodge", alpha = .5) +
  geom_jitter(inherit.aes = FALSE, aes(grp, score, fill=phase), position = position_jitter(0.2)) 
teunbrand
  • 33,645
  • 4
  • 37
  • 63
wythe4
  • 83
  • 4
  • Could you please give a minimal reproducible example. You may have a look to this post : https://stackoverflow.com/questions/10493084/ggplot2-jitter-and-position-dodge-together – Rémi Coulaud Jul 09 '20 at 18:24

2 Answers2

0

The default shape for points does not take the fill aesthetic

Compare

library(ggplot2)
ggplot(mtcars, aes(mpg, disp, fill = gear)) +
  geom_jitter()

ggplot(mtcars, aes(mpg, disp, color = gear)) +
  geom_jitter()

ggplot(mtcars, aes(mpg, disp, fill = gear)) +
  geom_jitter(shape = 21)

Created on 2020-07-09 by the reprex package (v0.3.0)

tjebo
  • 21,977
  • 7
  • 58
  • 94
0

Found a solution using: geom_point(position=position_jitterdodge())

This seems to jitter and dodge to separate the points.

wythe4
  • 83
  • 4