[R] Can't add error bars to existing line graph
John Fox
j|ox @end|ng |rom mcm@@ter@c@
Wed Jun 16 21:01:35 CEST 2021
Dear Bruno,
There are (at least) two errors here:
(1) I think that you misunderstand how interaction.plot(), and more
generally R base graphics, work. interaction.plot() doesn't return a
graphics object, but rather draws on a graphics device as a side effect.
Of course, interaction.plot() is a function and so it must return
something -- it invisibly returns NULL.
(2) I assume that you independently computed Scaphmeans and Scaphse,
although you didn't include the corresponding code in your message. In
any event, the arrows() function generally takes 4 arguments (x0, y0,
x1, y1), specifying the x and y coordinates of the endpoints of the
arrows. It's true that because your "arrows" are intended to be
vertical, you need not specify x1, which defaults to x0, but the other 3
arguments are necessary. See ?arrows for details.
I hope this helps,
John
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/
On 2021-06-15 9:02 a.m., Bruno.Salonen wrote:
>
> Hi all,
>
> I'm trying to add error bars to an existing line graph in base R.
>
> The basic line graph comes up just fine, but it does not show my error
> bars...
>
> Data frame = readscaphfileNEW
> Plot name = SCAPHLINEGRAPHNEW
> x axis = TEMP
> y axis = SCAPH.BPM
> Tracer = Year (SAME AS 'EXPERIMENT)
> Scaphmeans = means of SCAPH.BPM
> Scaphse = standard error of SCAPH.BPM
>
> Here is the code..
>
> SCAPHLINEGRAPHNEW <- interaction.plot(readscaphfileNEW$TEMP,
> readscaphfileNEW$EXPERIMENT, readscaphfileNEW$SCAPH.BPM,
> xlab = "Temperature (°C)", ylab = "Scaphognathite Rate (BPM)",
> main = "Scaphognathite",
> ylim = c(0,300), trace.label = "Year",
> type = "b", pch = c(19,17), fixed = TRUE)
> arrows(SCAPHLINEGRAPHNEW,Scaphmeans+Scaphse,SCAPHLINEGRAPHNEW,Scaphmeans-Scaphse,code=3,
> angle=90, length=0.1)
>
> Why are my error bars not showing? Is the 'arrows' line wrong?
>
> Thanks a million for your help, everybody.
>
> Here is my data set:
>
>> readscaphfileNEW
> EXPERIMENT TEMP SCAPH.BPM
> 1 2021 12 82
> 2 2021 12 58
> 3 2021 12 78
> 4 2021 12 59
> 5 2021 12 80
> 6 2021 12 100
> 7 2021 12 61
> 8 2021 12 103
> 9 2021 12 61
> 10 2021 17 100
> 11 2021 17 70
> 12 2021 17 83
> 13 2021 17 73
> 14 2021 17 143
> 15 2021 17 103
> 16 2021 17 73
> 17 2021 17 158
> 18 2021 17 95
> 19 2021 17 80
> 20 1939 12 158
> 21 1939 12 148
> 22 1939 12 152
> 23 1939 12 148
> 24 1939 12 160
> 25 1939 12 168
> 26 1939 12 152
> 27 1939 12 150
> 28 1939 12 187
> 29 1939 17 300
> 30 1939 17 302
> 31 1939 17 291
> 32 1939 17 240
> 33 1939 17 253
> 34 1939 17 207
> 35 1939 17 184
> 36 1939 17 224
> 37 1939 17 242
> 38 1939 17 236
>
> Bruno
>
>
>
> --
> Sent from: https://r.789695.n4.nabble.com/R-help-f789696.html
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
More information about the R-help
mailing list