Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding overlap when jittering points

Tags:

plot

r

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.

Jittered points without overlap

If anybody knows how to do this, preferably using some basic function, I'd be very happy to know.

like image 211
Backlin Avatar asked Aug 09 '12 18:08

Backlin


People also ask

How do you avoid overlapping plots in python?

Dot Size. You can try to decrease marker size in your plot. This way they won't overlap and the patterns will be clearer.

How do you stop Overplotting?

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.

What is the purpose of jittering?

Jittering is the act of adding random noise to data in order to prevent overplotting in statistical graphs.

What is jittering in scatter plot?

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.


1 Answers

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)

enter image description here

like image 132
bdemarest Avatar answered Nov 15 '22 13:11

bdemarest