首页 文章

计算和显示均值的置信区间

提问于
浏览
0

我现在有一个图表,显示每组距离的平均值,但是我很难在图中添加置信区间并显示它们 .

我的代码是:

TeamMeans<- read.csv(file = file.choose())
teamM=TeamMeans
graph6<-ggplot(aes(x=Team, y=Mean), data=teamM)
  + geom_point()
  + geom_smooth(size = 2, alpha = 0.35)
  + aes(group=1) 
  + labs(x= 'Team Names', y= 'Mean', title= 'Means of Throws Per Team') 
  + coord_flip() 
graph6

任何帮助将不胜感激!

1 回答

  • 0

    由于 team 是因子变量,因此使用带有错误栏的条形图更适合绘制此类数据的摘要 .

    # creating some data
    set.seed(12)
    teamM <- data.frame(team=rep(LETTERS[1:5],length=100), distance=rnorm(100,4,1))
    
    # creating the plot
    ggplot(teamM, aes(x=team, y=distance, fill=team)) + 
      stat_summary(fun.y = mean, geom = "bar") + 
      stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width=0.3) +
      labs(x= 'Team Names', y= 'Mean', title= 'Means of Throws Per Team\n') +
      theme_bw()
    

    结果:

    enter image description here

    显示数据摘要的另一种方法是使用 boxplot

    ggplot(teamM, aes(x=team, y=distance, fill=team)) + 
      geom_boxplot() + 
      labs(x= 'Team Names', y= 'Mean', title= 'Means of Throws Per Team\n') +
      theme_bw()
    

    给出:
    enter image description here

相关问题