+ Reply to Thread
Results 1 to 8 of 8

Thread: problem with abline and regression plot

  1. #1
    Points: 2,561, Level: 30
    Level completed: 74%, Points required for next Level: 39

    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with abline and regression plot



    I use 2.9.0
    when using the following commands with the attached lbw.txt

    lbw<-read.table("lbw.txt")
    reg<-(lbw$PDBB~lbw$PDMR)
    plot(lbw$PDMR,lbw$PDBB)
    abline(reg)

    I can't get the plot with the regression line

    Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
    plot.new has not been called yet.
    And a blank plot appears. ...

    What is strange is that the four following lines submitted together give a regression line but I get the same error if I submit these lines step by step

    Is there a solution?

    Thanks

    mboutsen
    statistician
    brussels university
    Attached Files

  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
    There are a few problems with your code.
    Firstly your code does not use any of the variables in lbw. The column names in lbw are:
    colnames(lbw)
    [1] "id" "agm" "pm" "nse" "fum" "trav" "hta" "iu" "cons" "pbb"

    Secondly
    reg<-(lbw$PDBB~lbw$PDMR)
    does not have a function in front of the brackets. For a linear model it would be for example:
    reg<-lm(lbw$pm~lbw$pbb)

    The following code works ok for me:
    Code: 
    lbw<-read.table("lbw.txt")
    reg<-lm(lbw$pm~lbw$pbb)
    plot(lbw$pbb,lbw$pm)
    abline(reg)
    Does this answer your query?

  3. #3
    Points: 2,561, Level: 30
    Level completed: 74%, Points required for next Level: 39

    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with abline and regression plot

    you are right, I didn't check the lbw.txt

    But even with the right code, I get the same problem
    I attached a printscreen

    What OS do you use?
    I'm using windows xp
    Last edited by mboutsen; 03-26-2010 at 12:52 PM.

  4. #4
    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
    I am also using Windows XP.
    The abline function requires the plot window to be open. If you submit the lines of code setwise, do you see the R Graphics window after executing the plot command?
    If so, do other functions work that add to the current plot, e.g.

    Code: 
    lbw<-read.table("lbw.txt")
    reg<-lm(lbw$pm~lbw$pbb)
    plot(lbw$pbb,lbw$pm, ylim=c(0,1.1*max(lbw$pm)))
    points(x=lbw$pbb, y=lbw$agm, col="red")
    If you can see the R Graphics window after the plot command and you cannot add additional points as in the example above then it appears that something is closing the R Graphics window before the abline or points functions are executed. At the moment, I cannot think of any reason for this unless you have another plot function which is masking the original.

  5. #5
    Points: 2,561, Level: 30
    Level completed: 74%, Points required for next Level: 39

    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    abline solved (more or less)

    Hi

    I get the same problem with the line beginning by points

    But if I put the two lines in a script and let execute the two lines together, I get the plot with the line!!!

    Very strange but real
    Is that a bug to notify to R?

    Luckily, I will deal further with R. I would like to introduce a R course in my university (epidemiology)

    Many thanks for your support!

    mboutsen

  6. #6
    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
    This is very strange. I don't think it can be a bug because it works on my copy of R. However, it might be something to do with your setup or perhaps the script editor you are using. The script editor I use is TinnR, but the R Editor and Windows notepad work ok as well.

    Have you tried the code on another computer?

    I have looked on R-Help for similar problems, but could not find anything. Similar problems have been reported with plots that use panels, but nothing with the basic plot function.

    It would be worth submitting a question to R-Help with the code and sample data to see if anyone else can help.

  7. #7
    Points: 479, Level: 9
    Level completed: 58%, Points required for next Level: 21

    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: problem with abline and regression plot

    Please Help me >>
    I have Problem in plotting with R, Actually at first this command was working but now Blank window is opening with this given error >>

    Error in plot.xy(xy.coords(x, y), type = type, ...) :
    plot.new has not been called yet

  8. #8
    RotParaTon
    Points: 46,233, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,077
    Thanks
    211
    Thanked 1,607 Times in 1,377 Posts

    Re: problem with abline and regression plot


    What are you trying to do? If you want to use 'lines' or 'points' or anything else like that then they only work if there is an open plot currently.

+ Reply to Thread

Similar Threads

  1. plot lines through regression model
    By Brendaa in forum R
    Replies: 1
    Last Post: 06-03-2010, 04:31 PM
  2. abline plots in the wrong place
    By SmoothJohn in forum R
    Replies: 7
    Last Post: 04-25-2010, 09:10 AM
  3. line plot problem
    By mcquilla in forum SAS
    Replies: 0
    Last Post: 01-10-2010, 07:22 AM
  4. Problem with Splus plot function
    By math_daddy in forum R
    Replies: 5
    Last Post: 08-20-2009, 03:06 PM
  5. problem graphing a stat plot....
    By Parsistamon in forum Statistics
    Replies: 0
    Last Post: 09-16-2007, 09:41 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