I need some help for a curious question of a friend of mine. She usually does some experiments (3-5 repeats for each exp) and then she calculates mean and standard deviation. In microsoft excel she writes something like the following sample mean sd a 1.25 0.35 b 2.65 0.65 c 3.45 0.50 She can do a vertical barplot graph just giving mean value and specifying the standard deviation value for each bar in the graph. My friend wants to know if it is possible to do the same with R. She has tried also with Open Office and seen that in that program you can plot mean values as bars but it is not possible to specify a different sd for each bar 'cause the program, if you ask to put the standard deviation, calculates a common sd using the mean values. I was not able to give her an answer for the barplot function in R. I have just said to her that it is likely due to the fact that using a barplot graph to plot mean and standard deviation values it is non a good practice, since the height (or the area) of bars should represent frequency and that putting a standard deviation in that way it is at least quite confusing for the reader to interpret the graph. Some scientific journal revisors discourage this practice. She should instead use a boxplot or just plotting the different repetition values for each sample as points and add a linea indicating the mean. But if this is correct why in some programs like open office you can plot bars with a common standard deviation???? when will you need this last type of graph? any suggestion? any help? thanks in advance Matteo
> DF <- data.frame(mean=c(1.25, 2.65, 3.45), sd=c(.35, .65, .5),+ row.names=letters[1:3]) > plot(1:3, DF$mean, ylim=range(DF$mean-2*DF$sd, DF$mean+2*DF$sd)) > segments(1:3, DF$mean-2*DF$sd, 1:3, DF$mean+2*DF$sd) hope this helps. spencer graves Matteo Vidali wrote:>I need some help for a curious question of a friend of mine. >She usually does some experiments (3-5 repeats for each exp) and then she >calculates mean and standard deviation. >In microsoft excel she writes something like the following > >sample mean sd >a 1.25 0.35 >b 2.65 0.65 >c 3.45 0.50 > >She can do a vertical barplot graph just giving mean value and specifying >the standard deviation value for each bar in the graph. > >My friend wants to know if it is possible to do the same with R. She has >tried also with Open Office and seen that in that program you can plot mean >values as bars but it is not possible to specify a different sd for each >bar 'cause the program, if you ask to put the standard deviation, calculates >a common sd using the mean values. >I was not able to give her an answer for the barplot function in R. I have >just said to her that it is likely due to the fact that using a barplot >graph to plot mean and standard deviation values it is non a good practice, >since the height (or the area) of bars should represent frequency and that >putting a standard deviation in that way it is at least quite confusing for >the reader to interpret the graph. Some scientific journal revisors >discourage this practice. She should instead use a boxplot or just plotting >the different repetition values for each sample as points and add a linea >indicating the mean. >But if this is correct why in some programs like open office you can plot >bars with a common standard deviation???? when will you need this last type >of graph? > >any suggestion? any help? >thanks in advance >Matteo > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
You want to read the help ?segments. Try the following to get the barplots: ymean=c(1.25,2.65,3.45) ysd=c(0.35,0.65,0.50) xpos=barplot(ymean,ylim=c(0,max(ymean)+max(ysd)),col='yellow') segments(xpos,ymean-ysd,xpos,ymean+ysd) HTH, Rob Baer ----- Original Message ----- From: "Matteo Vidali" <vidali at med.unipmn.it> To: <R-help at stat.math.ethz.ch> Sent: Friday, May 21, 2004 4:03 AM Subject: [R] bars with sd> I need some help for a curious question of a friend of mine. > She usually does some experiments (3-5 repeats for each exp) and then she > calculates mean and standard deviation. > In microsoft excel she writes something like the following > > sample mean sd > a 1.25 0.35 > b 2.65 0.65 > c 3.45 0.50 > > She can do a vertical barplot graph just giving mean value and specifying > the standard deviation value for each bar in the graph. > > My friend wants to know if it is possible to do the same with R. She has > tried also with Open Office and seen that in that program you can plotmean> values as bars but it is not possible to specify a different sd for each > bar 'cause the program, if you ask to put the standard deviation,calculates> a common sd using the mean values. > I was not able to give her an answer for the barplot function in R. I have > just said to her that it is likely due to the fact that using a barplot > graph to plot mean and standard deviation values it is non a goodpractice,> since the height (or the area) of bars should represent frequency and that > putting a standard deviation in that way it is at least quite confusingfor> the reader to interpret the graph. Some scientific journal revisors > discourage this practice. She should instead use a boxplot or justplotting> the different repetition values for each sample as points and add a linea > indicating the mean. > But if this is correct why in some programs like open office you can plot > bars with a common standard deviation???? when will you need this lasttype> of graph? > > any suggestion? any help? > thanks in advance > Matteo > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html>