2013-10-15 1 views
0

각 막대 그림 위에 오류 막대를 만들려고하지만 3 개의 그룹과 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

+0

난 당신이하고자 이해 y 축이 50에서 시작하지만, [Ben Bolker 's answer here] (http://stackoverflow.com/questions/11695502/different-starting-point-not-0-in-barplot-y-axis)를 읽을 수 있습니다./11695689 # 11695689) 인수가 0을 포함하는 축이없는 것에 대한 것입니다. 나는 여기에 'scale_x_discrete'가 필요하다고 생각하지 않는다. – Henrik

답변

0

그것은 종류의 그것이 출력으로보고 싶은 것이 무엇인지 말해 주지만, 내가 모은 것에서 이것은 아마도 당신이 원하는 것을 할 것입니다.

geom_errorbar(aes(ymin=HeartRate,ymax=HeartRate+StdError*2),position="dodge",width=.25) 

오류 막대를 x 축을 따라 이동하려면 position = dodge를 수정해야합니다. (대부분?) ...

geom_errorbar(aes(ymin=HeartRate-StdError,ymax=HeartRate+StdError),position=group-10,width=.25) 

또는

geom_errorbar(aes(ymin=HeartRate-StdError,ymax=HeartRate+StdError),position=Session-10,width=.25) 

또는를 나는 많은 문서를 볼 수 없습니다하지만 당신은 뭔가를 시도 할 수 있습니다이 :

 geom_errorbar(aes(ymin=HeartRate-StdError,ymax=HeartRate+StdError),position=x-10,width=.25) 
+0

오류 표시 줄을 원하는 곳에 이미지를 넣습니다. – cherner

+0

@cseb 오케이, 그럴 경우 내 수정이 당신이 찾고있는 것을 제공 했습니까? –

+0

아니, 그냥 yaxis에 오류 막대를 이동, 각 막대 음모의 중심에 그것을 만들기 위해 그것을 xaxis에 이동하는 방법을 궁금해. – cherner

관련 문제