1

I'm plotting summary stats in front of individual geom_points, but can't figure out how to add jitter to the plots. I think the issue is that I'm already using the position argument to move the High and Low water points away from each other.

    waterSymPop_p <- ggplot(aes(x = SymPop, y = Finish, fill = Water, color = Water), data = xanFull) +
  geom_point(position = position_dodge(width = 0.9)) +
  stat_summary(fun.data = "mean_cl_normal", geom = "pointrange", position = position_dodge(width = 0.9)) +
  coord_flip()

Here's the plot that produces (obviously not finished with the color scheme, etc) enter image description here

I'd like the point to be slightly jittered within each point group (ie, not in a straight line). Thanks for the help!


Answer: use position_jitterdodge

Amended code and new figure:

ggplot(aes(x = SymPop, y = Finish, fill = Water, color = Water), data = xanFull) +
  geom_point(position = position_jitterdodge(dodge.width = 0.9, jitter.width = 0.2)) +
  stat_summary(fun.data = "mean_cl_normal", geom = "pointrange", position = position_dodge(width = 0.9)) +
  coord_flip()

enter image description here

nrussell
  • 18,382
  • 4
  • 47
  • 60
jwb4
  • 175
  • 1
  • 7
  • 1
    you mean a jitter dodge http://docs.ggplot2.org/current/position_jitterdodge.html – Drey Jul 21 '16 at 18:31
  • Great! I knew it'd be something simple. I'll amend the post to reflect the solution. Thanks! – jwb4 Jul 21 '16 at 18:34
  • @jwb4 You should add your answer as an answer below rather than in the question. Nothing wrong with doing that, and then you can get it upvoted, and the question can be marked as answered. – beroe Jul 21 '16 at 22:45

1 Answers1

2

Drey answered this.

Answer: use position_jitterdodge

Amended code and new figure:

ggplot(aes(x = SymPop, y = Finish, fill = Water, color = Water), data = xanFull) +
  geom_point(position = position_jitterdodge(dodge.width = 0.9, jitter.width = 0.2)) +
  stat_summary(fun.data = "mean_cl_normal", geom = "pointrange", position = position_dodge(width = 0.9)) +
  coord_flip()

enter image description here

jwb4
  • 175
  • 1
  • 7