我想使每個酒吧上面的錯誤酒吧情節,但我有三組的酒吧情節,並且6酒吧情節,它的定位錯誤酒吧,每個組,但我想定位每個欄上方的每個錯誤欄。下面是我的數據是這樣的:gg陰謀錯誤酒吧定位
NewData
Group Session HeartRate StdError n sd
1 Novices one 71.89276 1.821146 29 9.807170
2 Experts one 66.40705 1.923901 26 9.810008
3 Novices two 71.38609 1.571261 29 8.011889
4 Experts two 67.79910 1.788151 26 9.117818
5 Novices three 71.79759 1.941730 29 10.456534
6 Experts three 67.04564 1.938620 26 9.885061
這裏是我的代碼:
plot_2 = ggplot(NewData, aes(x=Session, y=HeartRate, fill=Group)) +
theme_bw() +
geom_bar(position="dodge",stat="identity")+
scale_x_discrete(limits=c("one","two","three")) +
coord_cartesian(ylim = c(50, 80)) +
geom_errorbar(aes(ymin=HeartRate-StdError,ymax=HeartRate+StdError),position="dodge",width=.25)
下面是輸出:http://i.imgur.com/BrLB6Px.png
任何幫助,將不勝感激。謝謝!
OK--我找到了解決辦法,真的不知道怎樣和爲什麼它的工作原理,但這裏是我的新代碼:
dodge <- position_dodge(width=0.9)
plot_2 = ggplot(NewData, aes(x=Session, y=HeartRate, fill=Group)) +
geom_bar(position=dodge)+
scale_x_discrete(limits=c("one","two","three")) +
coord_cartesian(ylim = c(50, 80)) +
geom_errorbar(aes(ymin=HeartRate-StdError,ymax=HeartRate+StdError),position=dodge,width=.25)
而這裏的期望的結果:http://i.imgur.com/PodCeh5.png
我明白你想有一個從50開始的y軸,但是你可以閱讀[Ben Bolker的答案](http://stackoverflow.com/questions/11695502/different-starting-point-not-0-in-barplot-y-axis/11695689#11695689)針對沒有包含零的軸的參數。我不認爲你在這裏需要'scale_x_discrete'。 – Henrik