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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of raz
> Sent: Wednesday, November 27, 2013 7:23 AM
> To: r-help@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@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.

______________________________________________
R-help@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.

Reply via email to