Reputation: 85
I have translated a program from R to C++. The program in question runs multiple iterations of itself with different values then produces a histogram and plot. C++ graphs are finicky so I decided to save the values in csv format and graph them in R. The files are fairly large, for smaller size files, 10 iterations produces 23000 rows and 3 columns. Of course this increase drastically for 100 or 1000 iterations. The format of the csv files is 1,3,0.0107171 which corresponds to col num, row num and data. Then I run this into R:
>data<-read.csv(file.choose(),header=T)
>plot(data,type="b", pch=19, xlab="X", ylab="Y")
Error in plot.default(...) :
formal argument "type" matched by multiple actual arguments
As a side note:
> hist(data[,3], xlab="Step length (m)", main="")
the histogram works without any problems. Please tell me if i can provide any more details, I am not so good when it comes to R so I might be missing something obvious. Thanks in advance.
Upvotes: 6
Views: 41037
Reputation: 81
In my case, this indicated that my input data structure was not numeric.
I solved it using as.numeric
, as follows:
plot(as.numeric(df[1, 1:9]), as.numeric(df[2, 1:9]),
las = 2, type = "l",
col = colrs[3],lwd = lwds[1], ylim = c(0, 1.05*maxnumb), xlim = c(-0.6, yAx), main = weDraw, ylab = "OD 600", xlab = "hours", xaxt = "n")
Upvotes: 0
Reputation: 1
Sorry for late reply. I encountered this and it was due to passing the plot function a data.frame from inside another function. The work around was to simply do this:
do.plot <- function(df = plot.df[c(1, 2), ])
{
as.matrix(df)
plot(.....)}
Upvotes: -2
Reputation: 115382
You are passing a data.frame to plot
, which dispatches plot.data.frame
, which will, for a data.frame with more than 2 columns, call
pairs(data.matrix(data))
So you could pass arguments in ...
that are valid for pairs
(type
is not)
However I think you probably want to think about what you want to plot from your data
And then create your call to plot
(or perhaps matplot
) as required.
Upvotes: 8