【问题标题】:Calculating and Displaying Confidence Intervals of Means计算和显示均值的置信区间
【发布时间】:2014-06-05 00:22:06
【问题描述】:

我目前有一个图表,显示 R 中每组距离的平均值。但是我正在努力添加置信区间并将它们显示在图表上。

我的代码是:

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

任何帮助将不胜感激!

【问题讨论】:

标签: r ggplot2 mean confidence-interval


【解决方案1】:

由于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()

结果:

显示数据摘要的另一种方式是使用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()

给出:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多