Dirk Eddelbuettel <[EMAIL PROTECTED]> writes:

> On 18 June 2007 at 00:33, Roger Leigh wrote:
> | The errbar() function does not work correctly on a log axis, due
> | to the code assuming the axis is linear.
> | 
> | Here is a tiny testcase to demonstrate:
> | 
> | library(Hmisc)
> | x <- c(0.03,0.1,0.3,1,3,10,30)
> | y <- c(10,6,2,0.8,0.3,0.06,0.021)
> | sd <- c(5,2,1,0.3,0.1,0.2,0.08)
> | par(mfrow=c(2,1))
> | errbar(x,y,y-sd,y+sd)
> | errbar(x,y,y-sd,y+sd, log="x")
> | 
> | It should be possible for the code to check if par xlog=T and then
> | adjust the x±cap to cope with the log scale.

This is how I solved it (very crudely).  This code snippit assumes
vectors x, y (data series), and sd (the error).  colour is the line
colour.

    # Add error bars "by hand", for SD on a log axis.
    i <- 1
    for (i in 1: length(x)) {
      lower <- 0.90 * x[i]
      upper <- 1.12 * x[i]

      lines(c(x[i],x[i]),c(y[i]+sd[i], y[i]-sd[i]), col=colour, lty=1)
      lines(c(lower,upper), c(y[i]+sd[i], y[i]+sd[i]), col=colour, lty=1)
      lines(c(lower,upper), c(y[i]-sd[i], y[i]-sd[i]), col=colour, lty=1)
    }

It replaces "cap" with two factors for giving a nice even line over
the top and bottom of the error bar.  However, this would ideally be
replaced by a computed value to allow the user to specify the cap on
some sort of meaningful scale.


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.

Attachment: pgpp6TFXx7aDH.pgp
Description: PGP signature

Reply via email to