When reading scientific papers I often come across plots where points are jittered without overlaping each other. I suspect many of them are drawn with a program called GraphPad Prism, but surely there must be a way to do the same in R. Although it is not perfect (as with the red points below) I think it looks much better than random jittering.
If anybody knows how to do this, preferably using some basic function, I'd be very happy to know.
Dot Size. You can try to decrease marker size in your plot. This way they won't overlap and the patterns will be clearer.
Fixes for overplotting include reducing the size of points, changing the shape of points, jittering, tiling, making points transparent, only showing a subset of points, and using algorithms to prevent labels from overlapping.
Jittering is the act of adding random noise to data in order to prevent overplotting in statistical graphs.
The “jitter” option is a useful tool to help better visualize the data. “Jitter” adds random noise to the observations before generating the scatterplot, yielding a better visual sense of how many observations have each pair of X and Y values. “Jitter” does not modify the data permanently.
Here is a ggplot2 solution using geom_dotplot()
:
library(ggplot2)
set.seed(1234)
dat = data.frame(y=c(rpois(20, 4), rpois(20, 1), runif(20, 0, 20)),
category=rep(c("group_1", "group_2", "group_3"), c(20, 20, 20)))
dotplot_1 = ggplot(dat, aes(x=category, y=y)) +
geom_dotplot(aes(fill=category), binaxis="y",
stackdir="center", binwidth=0.8) +
stat_summary(fun.y=median, fun.ymin=median, fun.ymax=median,
geom="crossbar", width=0.7)
ggsave("dotplot_1.png", dotplot_1, width=6, height=4)
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