Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ggplot2 geom_jitter jitters in y direction?

I am very puzzled. When using ggplot2, many uses geom_jitter to add points to boxplots for instance. It is supposed to keep values on the Y-axis, at least as far as I know, and jitter values on the X-axis.

Using it today on two groups, 3 points per group, all the same values, I see it jitters values on the Y-axis.

library(ggplot2)

condition = c(rep("A", 3), rep("B", 3))
fraction = c(rep(100, 3), rep(100, 3))
df = data.frame(condition, fraction)


ggplot(df, aes(condition, fraction))+
  geom_jitter(width = 0.2)+
  labs(title = "",
       x = "", y = "fraction")+
  ylim(95,105)+
  theme_classic()

Graph is below (sorry too new to post an image apparently, so that’s a link):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

graph resulting from the code

Anyone?

>Solution :

Welcome to SO.

geom_jitter() jitters both horizontally and vertically. To avoid vertical jitter, set height = 0.

geom_jitter(height = 0, seed = 123)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading