指示条形图中统计上显着的差异USING R [英] Indicating the statistically significant difference in bar graph USING R

查看:189
本文介绍了指示条形图中统计上显着的差异USING R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是最初在这里提出的一个问题的重复:表明在条形图上有统计学上的显着差异,但是要求R代替python。

我的问题很简单。如果可能的话,我想在R中产生条形图,并指示不同条形之间的显着差异,例如,如果可能,使用ggplot2。产生这样的东西。我搜查了一遍,但找不到另一个问题,要求完全一样的东西。



解决方案

您可以使用 geom_path() annotate()得到相似的结果。对于这个例子,你必须自己决定合适的位置。在 geom_path()中提供了四个数字来获得连接线的小滴答。

  df <-data.frame(group = c(A,B,C,D),numb = c(12,24,36,48))
g< ; -ggplot(df,aes(group,numb))+ geom_bar(stat =identity)
g + geom_path(x = c(1,1,2,2),y = c(25,26 ,26,25))+
geom_path(x = c(2,2,3,3),y = c(37,38,38,37))+
geom_path(x = c 3,3,4,4),y = c(49,50,50,49))+
注释(text,x = 1.5,y = 27,label =p = 0.012)+
注释(text,x = 2.5,y = 39,label =p <0.0001)+
注释(text,x = 3.5,y = 51,label =p < 0.0001)


This is a repeat of a question originally asked here: Indicating the statistically significant difference in bar graph but asked for R instead of python.

My question is very simple. I want to produce barplots in R, using ggplot2 if possible, with an indication of significant difference between the different bars, e.g. produce something like this. I have had a search around but can't find another question asking exactly the same thing.

解决方案

You can use geom_path() and annotate() to get similar result. For this example you have to determine suitable position yourself. In geom_path() four numbers are provided to get those small ticks for connecting lines.

df<-data.frame(group=c("A","B","C","D"),numb=c(12,24,36,48))
g<-ggplot(df,aes(group,numb))+geom_bar(stat="identity")
g+geom_path(x=c(1,1,2,2),y=c(25,26,26,25))+
  geom_path(x=c(2,2,3,3),y=c(37,38,38,37))+
  geom_path(x=c(3,3,4,4),y=c(49,50,50,49))+
  annotate("text",x=1.5,y=27,label="p=0.012")+
  annotate("text",x=2.5,y=39,label="p<0.0001")+
  annotate("text",x=3.5,y=51,label="p<0.0001")

这篇关于指示条形图中统计上显着的差异USING R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆