Thursday, August 16, 2012

Plotting error bars in two dimensions

This came up today in a conversation with a postdoc in my lab, Graham Reynolds.

There are probably more elegant ways to do this, but one simple solution for plotting error bars in two dimensions is provided by just calling the gplots function plotCI twice. Here's an example:

# simulate data
x<-rnorm(n=5,mean=4); y<-rnorm(n=5,mean=4)
# here is a completely arbitrary simulation model
# for the standard error/deviation
SDx<-runif(5,0.1,1); SDy<-runif(5,0.1,1)
# plot
# first get the limits for x & y +- error
xlim<-c(min(x-SDx),max(x+SDx))
ylim<-c(min(y-SDy),max(y+SDy))
# now plot twice, remember to set add=TRUE
plotCI(x,y,SDx,err="x",xlim=xlim,ylim=ylim)
plotCI(x,y,SDy,err="y",add=TRUE)


The result is not too bad:
There must be a function that automates this. If you know which one - please feel free to post it in "comments."

2 comments:

  1. Huh. I always just used arrows() to do this...

    https://www.unt.edu/rss/class/splus/Rkickstart/kr_erbar.html

    ReplyDelete

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.