[R] Conditional error bars

William Dunlap wdunlap at tibco.com
Wed Nov 27 16:34:16 CET 2013


Change your two lines
>     arrows(xvals, mean, xvals, CI.H, angle=90,length=length)
>     arrows(xvals, mean, xvals, CI.L, angle=90,length=length)
to the one line
       arrows(xvals, mean, xvals, mean + sign(mean) * se, angle=90, length=length)

(I would also use a scatter plot instead of a barplot for this sort of thing and
draw both error bars.  I think the bars give a misleading impression of what
is going on.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of raz
> Sent: Wednesday, November 27, 2013 7:23 AM
> To: r-help at r-project.org
> Subject: [R] Conditional error bars
> 
> How can I condition any error bar function that use the arrows() function,
> such as 'CI.plot' (see example below) or 'error.bars', to draw only upper
> error bar (upper CI) if the bar value (mean) is positive and the lower
> error bar (lower CI) if bar value is negative?
> 
> CI.plot <- function(mean, se,length, ylim=c(-5, max(CI.H)), ...) {
>     CI.H <- mean+se
>     CI.L <- mean-se
>     xvals <- barplot(mean, ylim=ylim, ...) # Plot bars
>     arrows(xvals, mean, xvals, CI.H, angle=90,length=length)
>     arrows(xvals, mean, xvals, CI.L, angle=90,length=length)
> }
> 
> CI.plot(D,SE,0.01)
> 
> thanks,
> --
> \m/
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list