Douglas Bates bates at stat.wisc.edu
Mon Jan 18 16:57:09 CET 1999

```>>>>> "Peter" == Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:

Peter> John Logsdon <j.logsdon at lancaster.ac.uk> writes:
>> Example data: Item Size Year 1 0 1980 1 10 1981 1 14 1982 1 20
>> 1983 1 25 1984 1 30 1985 2 0 1980 2 5 1981 2 6 1982 2 8 1984 3 0
>> 1984 3 2 1985 4 0 1980 4 20 1981 4 30 1982 4 30 1984 4 35 1985
>>
>> This should produce 4 jagged lines on a plot, some shorter than
>> others.
>>
>> So far, I can see no simple equivalent of the \$GRA instruction
>> with the factors but presumably the trick is to fill up a matrix
>> with the data in a rather ugly loop storing the row number and
>> incrementing on a change in Item.  Ensure that the matrix is
>> NA-filled first and then use matplot to do the graph.

Peter> Hmm... Best I could think of till now was:

Peter> evalq(plot(Year,Size,type='n'),dfr)
Peter> invisible(lapply(split(dfr,dfr\$Item),
Peter> function(d)evalq(lines(Year,Size,lty=Item),d)))

A variant on this is to use the gapply function from the lme library.
This function applies a function to the subgroups of a data frame that
contains a grouping variable.

R> library( lme )
R> plot( value ~ year, data = ydat, type = "n" )
R> gapply( ydat, function(x) lines(x\$year, x\$value), form = ~ group )

If you convert the data frame into a groupedData object you can make
such a plot nearly a one-liner with the plot functions for groupedData
_except_ that those plots don't work in R.  They depend on trellis
graphics functions that are not (and probably won't be) available in R.

Sorry to tantalize but here is how you would get a trellis plot of
value ~ year by group in S with the nlme library

S> ydat <- groupedData( value ~ year | group, read.table("/tmp/ydat.dat"
S> trellis.device( motif )
S> plot( ydat )

If someone with a bit of time on their hands would write a function in
R using coplot that implemented some of the capabilities of the
trellis function xyplot, it would be possible to do this in R.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```