Hi there
Why cant I just plot such a simple dataset?
It seems thar R is finding some error in the dataset.
I have also tried with plot("V1", "V2"). Same result.
All the best

> read.table("clipboard", sep=",")
V1 V2
1 1 12
2 4 15
3 6 16
4 3 19
5 6 20
6 6 21
7 8 30
> x <- ("V1")
> y <- ("V2")
> plot(x, y)
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -Inf
>

The problem is that your code is assigning the character strings "V1" and "V2" to x and y, and not the numerical data. You need to assign the read.table results to a variable and then plot the variable e.g.

Code:

dat<-read.table("clipboard")
plot(dat)

Or, if you want to access the column variables V1 and V2 in dat and assign them to x and y you can do it as follows:

Code:

attach(dat)
x<-V1
y<-V2
detach(dat)
plot(x,y)

But, usually it is better to use the indexing method as follows

Hi,
I am having similar problem despite tryng the "attach" and other techniques previously described to match the variable types. I am trying to run the mathematical model but get the similar error message when plotting:

> require(FME)
> CSIfluc<-function(t, y, pars) {
+ with (as.list(c(y, pars)),{
+ N<-S+C+I
+ dS <- a*(1-N) - f*S*V - m*S - d*S
+ dC <- f*S*V + g*I + r*(1-N) - b2*C - m*C - d*C - b1*V*I
+ dI <- b2*C + b1*V*I - g*I - u*I
+ dV <- o*(C+I) - V*e
+ list(c(dS, dC, dI, dV),N)
+ })
+ }
> # parameter values
> pars <- list(a=0.2, m=0.0001, u=0.00003, b1=0.00023, b2=0.007, f=0.006, g=0.2, r=0.343, o=10.2, e=78, d=0.029)
> # initial conditions
> y = c(S=0.99,C=0.01,I=0,V=1)
> t <-seq(0,365, by=30)
> out1 <- as.data.frame(rk(y, t, CSIfluc, pars, method = "rk45dp7"))
> fluc1 <- stode(y = y, time=t, func = CSIfluc, parms = pars, pos = TRUE)
> fluc2 <- runsteady(y = y, func = CSIfluc, parms = pars, times = c(0, 1000))
> R0<-1/fluc1$S
> R02<-1/fluc2$S
> Re <- (1/fluc1$S * out1$S)
> Re2<- (1/fluc2$S * out1$S)
> mf <- par(mfrow = c(2,2))
> plot (fluc1$t, R0, type = "l", xlab = "Time (Days)", ylab = "R0")
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
> plot (fluc2$t, R02, type = "l", xlab = "Time (Days)", ylab = "R0")
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
> plot (fluc1$t, Re, type = "l", xlab = "Time (Days)", ylab = "Re")
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
> plot (fluc2$t, Re2, type = "l", xlab = "Time (Days)", ylab = "Re")
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf

I am on my way out the door right now and can't look at your code, however, if I can make a suggestion:

If you wrap your code with the code icon (the little pound sign) and eliminate extreneous symbols (like the "+" & ">") it makes running your code easier and you're more likely to get a prompt response.

Anyway, just at a quick peek you may need to use range() to find your xlim and ylim. You can then add this as one of the arguments to your plot.

type:

Code:

?ylim
?xlim

into the command line of [R] for additional info.

Last edited by trinker; 07-17-2011 at 03:13 PM.
Reason: spelling

"If you torture the data long enough it will eventually confess."
-Ronald Harry Coase -

Thanks for the reply. The "+" and ">" signs are just from the R console the runs from the R editor) and not the R editor (where the program is written without the "+" or ">"). I'll try the range option, but if you have any other thoughts on the matter, I would appreciate it. Thanks.

The "+" and ">" signs are just from the R console the runs from the R editor)

Yeah we know that - he was just saying that if you want help with code it's nice to give people a version of the code that's easy to copy and run (and read) right away. As it is somebody that wanted to run that code would have to line by line remove that extra stuff. The way you present it is alright to show us the error message but it would be annoying to try to debug it.

I tried the range() option and also looked at the help functions: ?xlim and ?ylim without success. Per your request, here is a portion of the program in the format you requested that I wish to run: