Error when creating time series line plots of xlsx file

I am trying to create time series line plots for two variables of an xlsx file that I imported into R. The code I used is listed below.

x <- myData$Google.Close
y <- myData$Amazon.Close
plot(Google.Close, Amazon.Close, type="1", main = "GoogleAmazonStock", xlab="Google.Close", ylab="Amazon.Close")
Error in plot(Google.Close, Amazon.Close, type = "1", main = "GoogleAmazonStock", :
object 'Google.Close' not found

I keep getting this error message when I try to run the code. The column headings of the xlsx dataset are "Google.Close" and "Amazon.Close"

Google.Close is a column of myData, it doesn't exist on its own, you have to reference it as myData$Google.Close.

Alternatively, use the "x" and "y" vectors you have defined.

x <- myData$Google.Close
y <- myData$Amazon.Close
plot(x, y, type="l", main = "GoogleAmazonStock", xlab="Google.Close", ylab="Amazon.Close")

Or use the "formula" syntax and the "data" argument

plot(Google.Close ~ Amazon.Close, data = myData, type="l", main = "GoogleAmazonStock", xlab="Google.Close", ylab="Amazon.Close")
1 Like

Thanks for your reply. I tried your suggestion and I got this error message.
x <- myData$Google.Close

y <- myData$Amazon.Close
plot(x, y, type="1", main = "GoogleAmazonStock", xlab="Google.Close", ylab="Amazon.Close")
Error in plot.xy(xy, type, ...) : invalid plot type '1'

Sorry, I just copied from your code, it should be an "l" not a "1"

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.