Dodging points and error bars with ggplot

后端 未结 1 1248
生来不讨喜
生来不讨喜 2020-12-09 12:19

Consider this data (note that foo is actually a factor.):

foo bar outcome ci
1   a   0.683333333 0.247447165
2   b   0.941666667 0.180356565
3           


        
相关标签:
1条回答
  • 2020-12-09 12:48

    One possibility is to group by 'bar'. Note that I also dodge the geom_text.

    dodge <- position_dodge(.1)
    
    ggplot(data = df, aes(x = foo, y = outcome, group = bar, label = bar)) + 
      geom_point(position = dodge) + 
      geom_errorbar(aes(ymin = outcome - ci, ymax = outcome + ci), position = dodge) + 
      geom_text(hjust = 2, position = dodge)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题