0

I need to plot two sets of data on one graph, and then use locator() to draw a vertical line at a given date. I have the code below and it works until after the plot function. The lines function is not adding the second dataset to my graph.

Can someone please help me understand what I'm doing incorrectly?

Thank you in advance

LMT <- read.csv("LMT.csv",header = T)
JNJ <- read.csv("JNJ.csv",header = T)

LMT$Date <- as.Date(LMT$Date)
JNJ$Date <- as.Date(JNJ$Date)

plot(y=LMT$Adj.Close, x=LMT$Date, ylim = c(0,500), type = "l")
lines(JNJ$Adj.Close,type = "l")
RBRN1231
  • 67
  • 5
  • 5
    Its likely the x or x ranges of the two data sets do not overlap. See https://stackoverflow.com/questions/49762125/text-and-second-line-is-not-being-displayed-with-plot-and-line. It's impossible to tell for sure without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 10 '22 at 20:47

0 Answers0