[R] Basic plot question: Figure 1.1 Pinheiro & Bates

Douglas Bates bates at stat.wisc.edu
Fri Oct 12 20:49:34 CEST 2007


On 10/12/07, David Afshartous <dafshartous at med.miami.edu> wrote:
> All,
> Sorry for overly simplistic question, but I can't seem to remember how to
> create the basic plot shown in Figure 1.1 of Pinheiro & Bates (2004; p.4).
> The y-axis delineates a factor (Rail) while the x-axis displays the
> distribution of a continuous variable (time) according to each level of the
> factor.  Didn't see it in archives but perhaps I'm not searching on correct
> key words, any help appreciated,
> David

> > library("nlme")
> > Rail
> Grouped Data: travel ~ 1 | Rail
>    Rail travel
> 1     1     55
> 2     1     53
> 3     1     54
> 4     2     26
> 5     2     37
> 6     2     32
> 7     3     78
> 8     3     91
> 9     3     85
> 10    4     92
> 11    4    100
> 12    4     96
> 13    5     49
> 14    5     51
> 15    5     50
> 16    6     80
> 17    6     85
> 18    6     83

That plot can be reproduced by

> library(lattice)
> data(Rail, package = "nlme")
> dotplot(Rail ~ travel, Rail)

However, this relies on the Rail$Rail factor being ordered by
increasing mean travel time, which is fine for the plot but may get in
the way of other uses of the data.  In a way we only want to assign an
order to the levels of the Rail factor for the purposes of the plot.

As Deepayan Sarkar mentions in his useR!2007 presentation
(http://user2007.org/program/presentations/sarkar.pd) he has done a
considerable amount of upgrading of the lattice package, relative to
the original design of Trellis graphics, in part to make the nlme
plots easier to create.  The version of the Rail data in the MEMSS
package removes the ordering on the levels of the Rail factor so it
defaults to the original order.  Compare

> data(Rail, package = "MEMSS")
> dotplot(Rail ~ travel, Rail)
> dotplot(reorder(Rail, travel) ~ travel, Rail)

The latter plot is the way I would recommend constructing that plot now.



More information about the R-help mailing list