Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid "Error in stripchart.default(x1, ...) : invalid plotting method" error?

Tags:

plot

r

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?

like image 478
Soumajit Avatar asked Mar 06 '15 16:03

Soumajit


1 Answers

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)
like image 61
alexforrence Avatar answered Oct 18 '22 18:10

alexforrence