抖动点时避免重叠 [英] Avoiding overlap when jittering points
本文介绍了抖动点时避免重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在阅读科学论文时,我经常遇到点抖动而不相互重叠的图.我怀疑他们中的许多人是用一个名为 GraphPad Prism 的程序绘制的,但肯定有一种方法可以做到在 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.
如果有人知道如何做到这一点,最好使用一些基本功能,我很乐意知道.
If anybody knows how to do this, preferably using some basic function, I'd be very happy to know.
推荐答案
这是一个使用 geom_dotplot()
的 ggplot2 解决方案:
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)
这篇关于抖动点时避免重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文