Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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, 1.5, 2.9, 3.8, 5.2) sd = c(0.1, 0.3, 0.2, 0.2, 0.4)  plot (x, y) 

How can I use the standard deviation to add error bars to each datapoint of my plot?

like image 207
John Garreth Avatar asked Feb 25 '13 08:02

John Garreth


People also ask

How do you add standard error bars in Boxplot R?

Adding error bars (whiskers) with stat_boxplot The default box plot in ggplot doesn't add the error bar lines, but you can add them with stat_boxplot , setting geom = "errorbar" . Note that you can change its width with width .


1 Answers

A solution with ggplot2 :

qplot(x,y)+geom_errorbar(aes(x=x, ymin=y-sd, ymax=y+sd), width=0.25) 

enter image description here

like image 150
juba Avatar answered Sep 23 '22 00:09

juba