Add error bars to show standard deviation on a plot in R

前端 未结 5 480
野性不改
野性不改 2020-11-27 03:51

For each X-value I calculated the average Y-value and the standard deviation (sd) of each Y-value

x  = 1:5
y  = c(1.1,         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 04:41

    In addition to @csgillespie's answer, segments is also vectorised to help with this sort of thing:

    plot (x, y, ylim=c(0,6))
    segments(x,y-sd,x,y+sd)
    epsilon <- 0.02
    segments(x-epsilon,y-sd,x+epsilon,y-sd)
    segments(x-epsilon,y+sd,x+epsilon,y+sd)
    

    enter image description here

提交回复
热议问题