Hi Bruno, The interaction.plot function plots the _levels_ of the x.factor argument, not the values of the variable that is coerced to a factor. This means that the temperature locations on the x axis are c(1,2), not c(12,17). The code below works for me:
readscaphfileNEW<-read.table(text="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", header=TRUE,stringsAsFactors=FALSE) 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) library(plotrix) Scaphmeans <-as.vector(by(readscaphfileNEW$SCAPH.BPM, readscaphfileNEW[,c("EXPERIMENT","TEMP")],mean)) Scaphse = as.vector(by(readscaphfileNEW$SCAPH.BPM, readscaphfileNEW[,c("EXPERIMENT","TEMP")],std.error)) dispersion(c(1,1,2,2),Scaphmeans,Scaphse) Note that you can get much the same plot using brkdn.plot (plotrix): brkdn.plot(SCAPH.BPM~EXPERIMENT+TEMP,data=readscaphfileNEW, xlab="Temperature C",pch=c(1,2)) legend(15,160,c(1939,2021),pch=c(1,2)) Jim On Thu, Jun 17, 2021 at 3:38 AM Bruno.Salonen <bruno.salo...@hotmail.com> 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@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. ______________________________________________ R-help@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.