Avoiding overlap when jittering points

后端 未结 1 1648
悲&欢浪女
悲&欢浪女 2021-02-20 04:43

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

1条回答
  •  你的背包
    2021-02-20 05:08

    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

    0 讨论(0)
提交回复
热议问题