[R] How can I put error bars on a barplot() ?

Marc Schwartz MSchwartz at medanalytics.com
Tue Dec 23 15:28:49 CET 2003


On Tue, 2003-12-23 at 08:04, olivier wrote:
> Hi all,
> 
> I am a relatively new R user... trying to put error bars (from SD
> values) on my data represented with barplot(). But I can't find any
> function or instruction to do so.
> Is there an easier way to do this than using segments() as I saw in an
> example in the R reference manual ? Then, can I define there graphical
> apparence ?
> 
> Thanks for help.
> 
> Regards
> 
> Olivier BUHARD


Olivier,

You can use either segments() or arrows() to place error bars on
barplots. 

Also, there is barplot2() in the gregmisc package on CRAN, which
provides this functionality and enables you to pass the error bar values
as arguments to the function.

As you may have noted, if you use either segments() or arrows(), the key
is to get the bar midpoints for proper line placement. The bar midpoints
are returned from the barplot() function and that is described in the
help for barplot().

If you should elect to use barplot2(), let me know if you have any
questions on its use.

Best regards,

Marc Schwartz




More information about the R-help mailing list