I saw a couple of posts on the similar problem but couldn't find a proper solution. Since the count in my data (reproducible example below) has duplicates, I need to print the overlapping points on the side of each other. People are using position_dodge but somehow the example below is not working for me.
library('ggplot2')
myData = data.frame(split = c(rep('a',10), rep('b',10)), count = c(20,27,21,20,24,23,21,25,22,22,35,37,32,32,32,32,31,33,32,31))
p = ggplot(myData, aes(split, count)) + geom_point(aes(colour=split), position=position_dodge(width=0.3))
p
#Getting the warning
ymax not defined: adjusting position using y instead
In this case you need position_jitter() not dodge.
ggplot(myData, aes(split, count)) + geom_point(aes(colour=split),
position=position_jitter(width=0.3))
Other alternative is to use geom_dotplot().
ggplot(myData, aes(split, count)) +
geom_dotplot(aes(fill=split),binaxis = "y",stackdir="center")

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With