# [R] Error Bar Issues

William Revelle lists at revelle.net
Sun Jun 6 06:28:22 CEST 2010

```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:
>Content-Type: text/plain
>Content-Disposition: inline
>Content-length: 4586
>
>
>Thanks for the suggestion...but R still doesn't like it.  Now I have 3 error
>messages.  It seems to dislike my *err=y* command.  I'm going to continue
>trying.  Thanks for your help!  If you happen to spot anything else, please
>let me know!
>
>thanks!
>beloitstudent
>
>
>On Sat, Jun 5, 2010 at 5:16 PM, Joris FA Meys [via R] <
>ml-node+2244611-1554261936-278019 at n4.nabble.com<ml-node%2B2244611-1554261936-278019 at n4.nabble.com>
>>  wrote:
>
>>  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,
>>
>>  Cheers
>>  Joris
>>
>>  On Sat, Jun 5, 2010 at 6:09 PM, beloitstudent
>><[hidden
>>email]<http://user/SendEmail.jtp?type=node&node=2244611&i=0>>
>>  wrote:
>>
>>  >
>>  > 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,
>>  >
>>  > And this is the error message I keep getting
>>  > Error in plotCI(x = Saline[, 1], y = Saline[, 2], uiw = Saline[, 3], liw
>>  =
>>  > uiw,  :
>>  > 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
>>  > --
>>  > View this message in context:
>>  http://r.789695.n4.nabble.com/Error-Bar-Issues-tp2244335p2244335.html
>>  > Sent from the R help mailing list archive at Nabble.com.
>>  >
>>  > ______________________________________________
>>  > [hidden email]
>><http://user/SendEmail.jtp?type=node&node=2244611&i=1>mailing
>>list
>>  > https://stat.ethz.ch/mailman/listinfo/r-help
>>  http://www.R-project.org/posting-guide.html
>>  > and provide commented, minimal, self-contained, reproducible code.
>>  >
>>
>>
>>
>>  --
>>  Ghent University
>>  Faculty of Bioscience Engineering
>>  Department of Applied mathematics, biometrics and process control
>>
>>  tel : +32 9 264 59 87
>>  [hidden email] <http://user/SendEmail.jtp?type=node&node=2244611&i=2>
>>  -------------------------------
>>  Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>>
>>  ______________________________________________
>>  [hidden email]
>><http://user/SendEmail.jtp?type=node&node=2244611&i=3>mailing
>>list
>>  https://stat.ethz.ch/mailman/listinfo/r-help
>>  http://www.R-project.org/posting-guide.html
>>  and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>  ------------------------------
>>   View message @
>>  http://r.789695.n4.nabble.com/Error-Bar-Issues-tp2244335p2244611.html
>>
>>
>>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Error-Bar-Issues-tp2244335p2244627.html
>Sent from the R help mailing list archive at Nabble.com.
>
>	[[alternative HTML version deleted]]
>
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help