如何在 ggplot2 中克服重叠点而没有抖动或透明度

发布于 2024-08-26 03:02:52 字数 454 浏览 4 评论 0原文

我开始使用ggplot2。我有一些小的 n(大约 30 左右)粒度数据,并且有很多重叠。抖动和 alpha(透明度)都不合适。相反,带有堆栈和偏移量的条形图效果最好,但我不知道如何在 ggplot2 中做到这一点。你知道吗?

要查看最终结果,请点击此图表

这是我几年前使用的脚本。

stripchart(SystData$DayTo1Syst~SystData$strain,vertical=TRUE,method="stack",pch=19,offset=.3,xlab="Strain",main="Rapidity of Systemic Disease Onset",ylab="Days post inoculation")

I am starting to use ggplot2. I have some small n (about 30 or so) granular data with lots of overlap. Neither jitter nor alpha (transparency) are suitable. Instead a stripchart with stack and offset do it best but I do not know how to do it in ggplot2. Do you know?

To see what the end result should be click on this graphic.

Here is the script I used a few years ago.

stripchart(SystData$DayTo1Syst~SystData$strain,vertical=TRUE,method="stack",pch=19,offset=.3,xlab="Strain",main="Rapidity of Systemic Disease Onset",ylab="Days post inoculation")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

李不 2024-09-02 03:02:52

您可以使用position_dodge

df <- data.frame(gp = rep(LETTERS[1:5], each =8), 
                 y = sample(1:4,40,replace=TRUE))
qplot(gp,y,data=df,order=y,position=position_dodge(width=0.5))

替代文字 http://img100.imageshack.us/img100/8760/dodgel.png

You can use position_dodge.

df <- data.frame(gp = rep(LETTERS[1:5], each =8), 
                 y = sample(1:4,40,replace=TRUE))
qplot(gp,y,data=df,order=y,position=position_dodge(width=0.5))

alt text http://img100.imageshack.us/img100/8760/dodgel.png

笑着哭最痛 2024-09-02 03:02:52
# your data
df <- data.frame(gp = rep(LETTERS[1:5], each =8), y = sample(1:4,40,replace=TRUE))
# calculate offsets
df <- ddply(df, .(y, gp), transform, offset = (1:length(gp)-1)/20)
qplot(gp, y, data=df) + stat_identity(aes(as.numeric(gp)+offset)) + theme_bw() 
# your data
df <- data.frame(gp = rep(LETTERS[1:5], each =8), y = sample(1:4,40,replace=TRUE))
# calculate offsets
df <- ddply(df, .(y, gp), transform, offset = (1:length(gp)-1)/20)
qplot(gp, y, data=df) + stat_identity(aes(as.numeric(gp)+offset)) + theme_bw() 
帅冕 2024-09-02 03:02:52

您想使用 ggplot2 中的 geom_dotplot

您可能会想使用:

ggplot(insert your arguments here) + geom_dotplot(binaxis = "y", stackdir = "center")

希望这有帮助。结果看起来非常干净,这就是我认为你想要的。

You want to use geom_dotplot from ggplot2

you will probably want to use:

ggplot(insert your arguments here) + geom_dotplot(binaxis = "y", stackdir = "center")

Hope this helps. The results will look really clean which is what I think you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文