[R] An empty grey diagram

Martin Maechler maechler at stat.math.ethz.ch
Mon Nov 22 16:44:27 CET 2010


>>>>> Stephen Liu <satimis at yahoo.com>
>>>>>     on Sat, 20 Nov 2010 00:12:07 -0800 (PST) writes:

    > Hi Josh and David,
    > Problem solved.

    > Both following steps work.

    > 1)
    >> ToothGrowth
    >> attach(ToothGrowth)
    >> plot(dose,len)   # this step is needed.  Don't close the diagram.  Otherwise 
    >> following command won't work.

    >> matrics=lm(len~dose)
    >> abline(matrics)

    > Graph displayed

    > 2)
    >> ToothGrowth
    >> attach(ToothGrowth)
    >> plot(dose, len)   # this step is needed.  Don't close the diagram.  Otherwise 
    >> following command won't work.

    >> abline(lm(len ~ dose, data = ToothGrowth))

    > Graph displayed

Well, it is  *VERY BAD*  style and error-prone practice  nowadays,
to attach a data set.
 [The only thing to attach() are  save()d data *files*;
  there it's often tidier to attach() instead of to load() ...]


I have not followed all the things you tried .. or did not try.

A much better way of achieving the above (and yes; *never* close
  the graphics window within these) should be

 plot (    len ~ dose, data=ToothGrowth)
 abline(lm(len ~ dose, data=ToothGrowth))

and you can see {if you use a fixed-width font in your e-mail,
    	    	 it "springs into your eyes"}
how nicely the formula notation of graphics alings with
the same in models.

If the above two simple lines do not work correctly,
then your R environment is "broken" in some way,
and maybe first doing  
    rm(list = ls())
may help.

Martin Maechler, 
ETH Zurich and R Core Team


    > B.R.
    > Stephen L


    > ----- Original Message ----
    > From: Joshua Wiley <jwiley.psych at gmail.com>
    > To: Stephen Liu <satimis at yahoo.com>
    > Cc: r-help at r-project.org
    > Sent: Sat, November 20, 2010 1:39:45 PM
    > Subject: Re: [R] An empty grey diagram

    > On Fri, Nov 19, 2010 at 9:35 PM, Stephen Liu <satimis at yahoo.com> wrote:
    >> Hi David,
    >> 
    >> 
    >>> What happens when you follow the directions... i.e. type:
    >>> plot.new()    #???
    >> 
    >> abline(lm(len ~ dose, data = ToothGrowth))
    >> plot.new()
    >> 
    >> The grey background changes to white, still an empty graph

    > You cannot just use abline() on an empty graphic (well, you can but
    > you get an empty graph).  Please actually run my code, it will create
    > a scatter plot, then add a line.  Do not close the graphic device in
    > between.

    > with(ToothGrowth, plot(dose, len))
    > abline(lm(len ~ dose, data = ToothGrowth))




    > ______________________________________________
    > R-help at r-project.org mailing list
    > 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