+ Reply to Thread
Results 1 to 8 of 8

Thread: Problem with plotting in R

  1. #1
    Points: 1,801, Level: 25
    Level completed: 1%, Points required for next Level: 99

    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with plotting in R




    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
    >

  2. #2
    TS Contributor
    Points: 5,565, Level: 48
    Level completed: 8%, Points required for next Level: 185

    Location
    St Albans, UK
    Posts
    257
    Thanks
    0
    Thanked 7 Times in 5 Posts
    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
    Code: 
    x<-dat[,"V1"]
    y<-dat[,"V2"]
    plot(x,y)

  3. #3
    Points: 828, Level: 15
    Level completed: 28%, Points required for next Level: 72

    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem with plotting in R

    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

    Any suggestions would be appreciated? Thank you.

    Anil Panackal, M.D., Sc.M., FACP

  4. #4
    ggplot2orBust
    Points: 36,766, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,010
    Thanks
    1,418
    Thanked 776 Times in 691 Posts

    Re: Problem with plotting in R

    apanackal,

    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 04:13 PM. Reason: spelling
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  5. #5
    Points: 828, Level: 15
    Level completed: 28%, Points required for next Level: 72

    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem with plotting in R

    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.

  6. #6
    Beep
    Points: 63,905, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardFrequent PosterActivity Award
    Dason's Avatar
    Location
    Ames, IA
    Posts
    11,364
    Thanks
    268
    Thanked 2,208 Times in 1,887 Posts

    Re: Problem with plotting in R

    Quote Originally Posted by apanackal View Post
    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.

  7. #7
    Probably A Mammal
    Points: 19,460, Level: 88
    Level completed: 22%, Points required for next Level: 390
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,208
    Thanks
    294
    Thanked 498 Times in 453 Posts

    Re: Problem with plotting in R

    It's also nice if you use BB tags for a code block (as used above). For example

    [code]... some code here ...[/code] produces,

    Code: 
    ... some code here ...
    You should make it so we could copy whatever is in that code block and run it in R for ourselves.

  8. #8
    Points: 828, Level: 15
    Level completed: 28%, Points required for next Level: 72

    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem with plotting in R


    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:

    Code: 
    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")
    plot (fluc2$t, R02, type = "l", xlab = "Time (Days)", ylab = "R0")
    plot (fluc1$t, Re, type = "l", xlab = "Time (Days)", ylab = "Re")
    plot (fluc2$t, Re2, type = "l", xlab = "Time (Days)", ylab = "Re")
    Last edited by Dason; 07-18-2011 at 09:25 AM. Reason: Added code tags

+ Reply to Thread

           




Similar Threads

  1. Plotting the log-likelihood for LM
    By thedreamshaper in forum R
    Replies: 8
    Last Post: 03-15-2011, 08:21 PM
  2. plotting a CDF from PDF
    By maybe in forum Probability
    Replies: 11
    Last Post: 03-10-2011, 04:21 PM
  3. Plotting 3 Lines on the same Plot
    By techintern4000 in forum SAS
    Replies: 0
    Last Post: 07-08-2009, 02:39 PM
  4. Plotting x, y, z coordinates
    By AlyssaK in forum Other Software
    Replies: 2
    Last Post: 02-09-2009, 01:58 PM
  5. Plotting PPV vs. NPV, why?
    By pufftissue in forum Biostatistics
    Replies: 0
    Last Post: 10-01-2008, 01:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats