Can't add error bars to existing line graph in base R

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...

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,ScaphmeansNEW+seNEWSCAPH,SCAPHLINEGRAPHNEW,ScaphmeansNEW-seNEWSCAPH,code=3, angle=90, length=0.1)

Error in arrows(SCAPHLINEGRAPHNEW, ScaphmeansNEW + seNEWSCAPH, SCAPHLINEGRAPHNEW, : invalid graphics state

Why are my error bars not showing? Is the 'arrows' line wrong?

Thanks a million for your help, everybody.

Here is my data...

> dput(readscaphfileNEW)
structure(list(EXPERIMENT = c("2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021", 
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "1939", 
"1939", "1939", "1939", "1939", "1939", "1939", "1939", "1939", 
"1939", "1939", "1939", "1939", "1939", "1939", "1939", "1939", 
"1939", "1939"), TEMP = c(12L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 17L, 17L, 17L, 17L, 17L, 
17L, 17L, 17L, 17L, 17L), SCAPH.BPM = c(82, 58, 78, 59, 80, 100, 
61, 103, 61, 100, 70, 83, 73, 143, 103, 73, 158, 95, 80, 158, 
148, 152, 148, 160, 168, 152, 150, 187, 300, 302, 291, 240, 253, 
207, 184, 224, 242, 236)), row.names = c(NA, -38L), class = "data.frame")
  • Bruno

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:


Short Version

You can share your data in a forum friendly way by passing the data to share to the dput() function.
If your data is too large you can use standard methods to reduce it before sending to dput().
When you come to share the dput() text that represents your data, please be sure to format your post with triple backticks on the line before your code begins to format it appropriately.

```
( example_df <- structure(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, 5.4, 4.6, 
5, 4.4, 4.9), Sepal.Width = c(3.5, 3, 3.2, 3.1, 3.6, 3.9, 3.4, 
3.4, 2.9, 3.1), Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 
1.4, 1.5, 1.4, 1.5), Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2, 
0.4, 0.3, 0.2, 0.2, 0.1), Species = structure(c(1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L), .Label = c("setosa", "versicolor", "virginica"
), class = "factor")), row.names = c(NA, -10L), class = c("tbl_df", 
"tbl", "data.frame")))
```

I have not done this type of thing for a long time but IIRC, you cannot store a base graph so SCAPHLINEGRAPHNEW will return NULL. The CI arrows need to be with in line with the graph. Also your code does not show how you are calculating Scaphmeans & Scaphse and it probably should for completeness sake.

# A very quick example of how to draw an arrow on a graph.
plot(1:10)
text(2,5, "Point 5 ", cex=.8)
arrows(3,5, 4.5, 5)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.