中断或没有功能区 ggplot geomribbon 或 stat_summary

发布于 2025-01-11 11:42:52 字数 2293 浏览 0 评论 0原文

我有一个看起来像这样的 df:

   ID Genotype Time10min  N        mean          sd           se          ci
43  1   k_DMSO        43 10 0.029318750 0.009793853 0.0030970883 0.007006100
44  1   k_DMSO        44 10 0.008825716 0.005164837 0.0016332648 0.003694702
45  1   k_DMSO        45 10 0.008466507 0.002879642 0.0009106228 0.002059972
46  1   k_DMSO        46 10 0.005871386 0.003848483 0.0012169970 0.002753039
47  1   k_DMSO        47 10 0.003126562 0.004755841 0.0015039288 0.003402123
48  1   k_DMSO        48 10 0.005546801 0.003725496 0.0011781053 0.002665059

我想绘制一个图表,其中 y 轴为“mean”,x 轴为“Time10min”。

为此,我想要使用此函数计算“基因型”指定的组内所有平均值的平均值:

  ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)

我得到每组一行的平均值,这就是我想要的。

然后我想添加一个基于 sem 的 geom_ribbon 。

我尝试了以下两个选项:

  ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)+
  geom_ribbon(aes(group=Genotype, fill=Genotype,ymin=mean-se, ymax=mean+se), alpha=0.5)

这给了我一个非常混乱的功能区,看起来像这样: graph

在更新我的 R 之前有效的其他选项是这个:

 ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)+
  stat_summary(aes(group=Genotype, fill=Genotype),geom="ribbon",fun.data = mean_cl_boot, alpha= 0.5)

现在我不断收到这样的错误:

Warning: Computation failed in `stat_summary()`:

数据类型是:

'data.frame':   36100 obs. of  8 variables:
 $ ID       : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Genotype : Factor w/ 10 levels "w_DMSO","h_DMSO",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ Time10min: int  1 2 3 4 5 6 7 8 9 10 ...
 $ N        : num  10 10 10 10 10 10 10 10 10 10 ...
 $ mean     : num  0.026 0.0341 0.0312 0.0173 0.0114 ...
 $ sd       : num  0.00801 0.0047 0.01085 0.01521 0.00868 ...
 $ se       : num  0.00253 0.00149 0.00343 0.00481 0.00274 ...
 $ ci       : num  0.00573 0.00336 0.00776 0.01088 0.00621 ...

请问,有人可以帮我在这个图上画一条漂亮的丝带吗?

谢谢你!

I have a df that looks like this:

   ID Genotype Time10min  N        mean          sd           se          ci
43  1   k_DMSO        43 10 0.029318750 0.009793853 0.0030970883 0.007006100
44  1   k_DMSO        44 10 0.008825716 0.005164837 0.0016332648 0.003694702
45  1   k_DMSO        45 10 0.008466507 0.002879642 0.0009106228 0.002059972
46  1   k_DMSO        46 10 0.005871386 0.003848483 0.0012169970 0.002753039
47  1   k_DMSO        47 10 0.003126562 0.004755841 0.0015039288 0.003402123
48  1   k_DMSO        48 10 0.005546801 0.003725496 0.0011781053 0.002665059

I want to plot a graph with "mean" on the y-axis and "Time10min" on the x-axis.

For this I want the mean across all means within a group specified by "Genotype" using this function:

  ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)

I get one line per group as mean which is what I want.

I then want to add a geom_ribbon based on sem.

I tried the following 2 options:

  ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)+
  geom_ribbon(aes(group=Genotype, fill=Genotype,ymin=mean-se, ymax=mean+se), alpha=0.5)

This gives me a very disrupted ribbon looking something like this:
graph

The other options that worked before updating my R is this one:

 ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)+
  stat_summary(aes(group=Genotype, fill=Genotype),geom="ribbon",fun.data = mean_cl_boot, alpha= 0.5)

Now I keep getting an error like this:

Warning: Computation failed in `stat_summary()`:

The data types are:

'data.frame':   36100 obs. of  8 variables:
 $ ID       : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Genotype : Factor w/ 10 levels "w_DMSO","h_DMSO",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ Time10min: int  1 2 3 4 5 6 7 8 9 10 ...
 $ N        : num  10 10 10 10 10 10 10 10 10 10 ...
 $ mean     : num  0.026 0.0341 0.0312 0.0173 0.0114 ...
 $ sd       : num  0.00801 0.0047 0.01085 0.01521 0.00868 ...
 $ se       : num  0.00253 0.00149 0.00343 0.00481 0.00274 ...
 $ ci       : num  0.00573 0.00336 0.00776 0.01088 0.00621 ...

Please, can someone help me to get a nice ribbon onto this plot?

Thank you!

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

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

发布评论

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