I have a simple, single data file test.txt
which contains:
1
5
7
9
11
I want to plot this file with index numbers. I have tried the following:
mydata<-read.table("test.txt")
sq<-seq(1,5)
x<-data.frame(sq)
plot(x,mydata)
But the plot is not generated. Instead, an error message is shown:
Error in stripchart.default(x1, ...) : invalid plotting method
Can you point out what I'm doing wrong, or suggest a better solution?
The issue is because plot()
is looking for vectors, and you're feeding it one data.frame and one vector. Below is an illustration of some of your options.
mydata <- seq(1,5) # generate some data
sq <- seq(1,5)
plot(sq, mydata) # Happy (two vectors)
x <- data.frame(sq) # Put x into data.frame
plot(x, mydata) # Unhappy (one data.frame, one vector) (using x$seq works)
##Error in stripchart.default(x1, ...) : invalid plotting method
x2 <- data.frame(sq, mydata) # Put them in the same data.frame
##x2
## sq mydata
##1 1 1
##2 2 2
##3 3 3
##4 4 4
##5 5 5
plot(x2) # Happy (uses plot.data.frame)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With