Skip to content

Error Bar Issues

5 messages · beloitstudent, Joris Meys, William Revelle

#
Hello all,

I am an undergraduate student who is having syntax issues trying to get
error bars on my graph.  

This is the data, which I assigned the name "Saline" to. 
 Time       Average       SEM
1   -20      0.000000     0.0000000
2
3    30      0.000000     0.0000000
4    45      3.227902     0.7462524
5    60      5.066664     1.1623944
6    80      6.107491     1.5027762
7   110     6.968231     1.3799637
8   140     7.325713     1.2282053
9   200     7.875194     1.1185175
10  260    6.513927     0.5386359
11  320    4.204342     0.6855906

This is the command that I typed in to get my error bars.

plotCI(x=Saline [,1],y=Saline [,2], uiw=Saline [,3], liw=uiw, err=y, pch=21,
pt.bg=par("bg"), cex=1.5, lty=1, type="o", gap=0, sfrac=0.005,
xlim=c(-21,340),xaxp=c(-20,320,11), xlab="Time (min)", ylim=c(0,12),
yaxp=c(0,12,11), ylab="Arterial Plasma Acetaminophen (?g/mL)", las=1,
font.lab=2, add=TRUE)

And this is the error message I keep getting
Error in plotCI(x = Saline[, 1], y = Saline[, 2], uiw = Saline[, 3], liw =
uiw,  : 
  object 'uiw' not found
In addition: Warning message:
In if (err == "y") z <- y else z <- x :
  the condition has length > 1 and only the first element will be used

Now, to me, the command seems correct.
I want the error bars to show up where the points on my graph are...so the x
coordinates should be my time (aka Saline [1]) and the y coordinates should
be my Averages (aka Saline [2])  and my upper and lower limits to my
confidence interval should be the SEM from Saline [3], but something is
wrong with this and I cannot figure out what it is.  If anyone has
suggestions I would be very grateful.  Thanks for your help!

beloitstudent
#
you can't refer to an argument within a function call. Try

uiw <- Saline[,3]

plotCI(x=Saline [,1],y=Saline [,2], uiw=uiw, liw=uiw, err=y, pch=21,
pt.bg=par("bg"), cex=1.5, lty=1, type="o", gap=0, sfrac=0.005,
xlim=c(-21,340),xaxp=c(-20,320,11), xlab="Time (min)", ylim=c(0,12),
yaxp=c(0,12,11), ylab="Arterial Plasma Acetaminophen (?g/mL)", las=1,
font.lab=2, add=TRUE)

Cheers
Joris
On Sat, Jun 5, 2010 at 6:09 PM, beloitstudent <schurrk at beloit.edu> wrote:

  
    
#
Dear Beloitstudent;


Although Ben Bolker will have to give you the 
definitive answer, the following will do what I 
think you want to do.


library(plotrix)   #for those of us who don't know where plotCI comes from
#give us the data:

Saline <- structure(list(Time = c(-20L, NA, 30L, 45L, 60L, 80L, 110L, 140L,
200L, 260L, 320L), Average = c(0, NA, 0, 3.227902, 5.066664,
6.107491, 6.968231, 7.325713, 7.875194, 6.513927, 4.204342),
     SEM = c(0, NA, 0, 0.7462524, 1.1623944, 1.5027762, 1.3799637,
     1.2282053, 1.1185175, 0.5386359, 0.6855906)), .Names = c("Time",
"Average", "SEM"), class = "data.frame", row.names = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11"))

# First  draw the  points
plotCI(x=Saline [,1],y=Saline [,2], uiw=Saline [,3], err="y",
  pt.bg=par("bg"),pch=21, cex=1.5 ,gap=0, sfrac=0.005,
xlim=c(-20,340),xaxp=c(-20,320,17), xlab="Time (min)", ylim=c(0,12),
  yaxp=c(0,12,12), ylab="Arterial Plasma Acetaminophen (?g/mL)", las=1,
font.lab=2)    #draws the points

plotCI(x=Saline [,1],y=Saline [,2], uiw=Saline [,3], err="y",
pt.bg=par("bg"),pch=21, cex=1.5 ,gap=0, sfrac=0.005,
xlim=c(-20,340),xaxp=c(-20,320,17), ylim=c(0,12),
yaxp=c(0,12,12), las=1,
font.lab=2,add=TRUE,type="o")   #puts the lines in and gives a message

You will get a warning message the type is 
obsolete, but at least you have your graph.

Bill
At 3:51 PM -0700 6/5/10, beloitstudent wrote:
#
On Sun, Jun 6, 2010 at 12:51 AM, beloitstudent <schurrk at beloit.edu> wrote:
Off course, same problem: You're referring to an object y in your
command. But you have no object named y in your workspace, so R can't
continue.

Look at the help files:
?plotCI

You'll see you have to put quotation marks around y, like William
showed you. Next to that, please also define from which package you
use a plot. plotCI can be found in the gplots package and in the
plotrix package.

Cheers
Joris

Either you define all input for the function before you run it, or you
use the double quotes like William showed