[R] abline function : plot.new has not been called yet

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sun Dec 14 09:13:17 CET 2014


The abline function is part of base graphics (read the help ?abline... it is part of the "graphics" package).

The xyplot function is part of the lattice package... a clone of the original "trellis" package from the S software. The two approaches to graphics don't play well together.

Once you know to keep this distinction in mind, you can probably find examples on the web, such as [1], or in help files such as ?panel.abline.

[1] http://apcg.uoregon.edu/GeogR/topics/lattice.htm
 
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On December 13, 2014 11:05:52 PM PST, Frederic Ntirenganya <ntfredo at gmail.com> wrote:
>Hi All,
>
>I would like to have an idea of how I can solve this error.
>
>I am getting the following error in plotting:
>
>> abline(regn,col='red',lwd=1.5 , data=BUTemp)
>Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
>  plot.new has not been called yet
>
>This is the str of my data set
>
>> str(BUTemp)
>'data.frame':    7671 obs. of  6 variables:
> $ Year : int  1971 1971 1971 1971 1971 1971 1971 1971 1971 1971 ...
>$ Month: Factor w/ 12 levels "Aug","Sep","Oct",..: 2 2 2 2 2 2 2 2 2 2
>...
> $ Day  : int  1 2 3 4 5 6 7 8 9 10 ...
> $ Rain : num  0 0 0 0 0 0 0 0 0 0 ...
> $ Tmax : num  24.3 25 25.6 26.5 27.8 27.5 25.7 25.1 26.5 25.1 ...
> $ Tmin : num  13.5 13.2 12.7 12.7 12.2 14 13.2 12.3 12.8 11.7 ...
>
>The code I am using is :
>
>require(latticeExtra) # trellis plot for temperature and rain.
>require(lattice)
>
>levels(BUTemp$Month) <- c("Aug", "Sep", "Oct", "Nov", "Dec", "Jan",
>                          "Feb", "Mar", "Apr", "May", "Jun", "Jul")
>
>xyplot(BUTemp$Tmin + BUTemp$Tmax ~ BUTemp$Year | BUTemp$Month,
>       data =BUTemp , type = "b", pch=19)
>
>regn=lm(BUTemp$Tmin + BUTemp$Tmax ~ BUTemp$Year)
>
>abline(regn,col='red',lwd=1.5)
>summary(regn)
>
>Thanks  for your help.
>
>Regards,
>Frederic.
>Frederic Ntirenganya
>Maseno University,
>African Maths Initiative,
>Kenya.
>Mobile:(+254)718492836
>Email: fredo at aims.ac.za
>https://sites.google.com/a/aims.ac.za/fredo/
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list