Connect mean points of error bars

前端 未结 3 1841
萌比男神i
萌比男神i 2021-01-15 19:08

In ggplot2 I\'m attempting a simple thing that I just can\'t get for some reason. I have adjusted means and SE in a data frame and want to plot the means, error bars and th

3条回答
  •  没有蜡笔的小新
    2021-01-15 20:03

    As an alternative to mnel's answer, you could create a new variable, so that you have a column where all 3 groups have the same value:

     data1$all <- "All"
    

    And then use that as the group aesthetic for your line:

    ggplot(data1, aes(x=group, y=estimate)) + 
        geom_errorbar(aes(ymin=estimate-SE, ymax=estimate+SE), 
            colour="black", width=.1, position=pd) +
        geom_line(aes(x=group, y=estimate, group=all)) + 
        geom_point(position=pd, size=4)
    

    Mnel's answer is probably more elegant, but this might work better if the groups aren't numbers and can't be converted to numeric so straightforwardly.

提交回复
热议问题