1

In R ggplot2, when I plot all zeros and use geom_jitter(), some variations are automatically added to zeros. How can I undo that? I still want all points at 0 y axis.

y = rep(0,100)

x = rep(c("A","B","C","D"),25)

D = data.frame(x,y)

library(ggplot2)

ggplot(D,aes(x=x,y=y))+geom_boxplot() + geom_jitter()

enter image description here

John
  • 1,779
  • 3
  • 25
  • 53

1 Answers1

2

If you need to keep the dots and spread them horizontally, you can use geom_jitter(height = 0). This will force the vertical variation/jitter to zero, but still allows the points to "jitter" horizontally.

ggplot(D, aes(x = x, y = y)) +
    geom_boxplot() +
    geom_jitter(height = 0)
JasonAizkalns
  • 20,243
  • 8
  • 57
  • 116
  • The editors of ggplot could make geom_jitter so that the dots distribute evenly, instead of randomly. Despite my jitter, I still have points that overlap... – Mehdi.K Feb 13 '18 at 13:03