点图“分箱/分组”在R中

发布于 2025-01-10 09:05:20 字数 1186 浏览 6 评论 0原文

我有 5 个数据集,每个数据集都有一个值列和一个组列。

数据

每个数据集都有不同的“组”值。 它们连接在一起形成 1 个大数据集,每个数据集都由其“组”值清楚地分隔开

。分开:
理想点图

然而,我目前拥有的是以下内容: currentplot

由于大多数数据点位于 2-3 范围内,因此它们彼此堆叠,结果绘图的数据点溢出到其他组

这是我当前使用的绘图代码:

p<-ggplot(new_df, aes(x=group, y=ploidy)) + 
  geom_dotplot(binaxis='y', stackdir='centerwhole', binwidth = 0.5, position = "dodge", stackgroups = TRUE, dotsize = 0.2)

ggplot(new_df, aes(x=group, y=ploidy)) + 
  geom_dotplot(binaxis='y', stackdir='centerwhole',
               stackratio=1.5, dotsize=0.2, stackgroups = TRUE)
p + scale_x_discrete(limits=c("1", "2", "3", "4", "5"))
p + stat_summary(fun=median, geom="point", shape=18,
                 size=3, color="red")

任何人都可以帮助指出我犯了什么错误以及如何修复它?我尝试过调整许多不同的参数并遵循文档,但 R 不是我的主要语言,我遇到了麻烦。 任何帮助将不胜感激,谢谢。

I have 5 datasets, each with a value column and a group column.

data

Each dataset has a different 'group' value.
They're joined together to make 1 big dataset, each clearly separated by its 'group' value

I'm trying to create a dotplot that neatly separates the groups by themselves, kind of like the following, where the M and F groups are clearly separated:
ideal dotplot

What I currently have, however, is the following: current plot

Since most of the datapoints sit around the 2-3 range, they are stacked above each other and the resulting plot has datapoints that are overflowing to the other groups

This is the plotting code I'm currently using:

p<-ggplot(new_df, aes(x=group, y=ploidy)) + 
  geom_dotplot(binaxis='y', stackdir='centerwhole', binwidth = 0.5, position = "dodge", stackgroups = TRUE, dotsize = 0.2)

ggplot(new_df, aes(x=group, y=ploidy)) + 
  geom_dotplot(binaxis='y', stackdir='centerwhole',
               stackratio=1.5, dotsize=0.2, stackgroups = TRUE)
p + scale_x_discrete(limits=c("1", "2", "3", "4", "5"))
p + stat_summary(fun=median, geom="point", shape=18,
                 size=3, color="red")

Can anyone help point out what mistake I'm making and how to fix it? I've tried tweaking many different parameters and following the documentation but R isn't my main language and I'm running into trouble.
Any help would be appreciated, thank you.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文