我目前有一张图表显示每组距离的平均值,但是我很难在图中添加置信区间并显示它们。
我的代码是:
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
任何帮助将不胜感激!
答案 0 :(得分: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()
结果:
显示数据摘要的另一种方法是使用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()
给出: