[R] lattice: cumsum and xyplot

Wolfram Fischer wolfram at fischer-zim.ch
Fri Jun 11 09:17:39 CEST 2004

I want to display cumulative summary functions with lattice.

First I tried to get cumulated data:

    d.cum <- with( barley, by( yield, INDICES=list(site=site,year=year), FUN=cumsum ) )

I got a list of vectors.
I tried to get a dataframe which I could use in xyplot.
But neither of the following functions led to the goal:

    d.cum.df1 <- as.data.frame.list( d.cum )
    d.cum.df2 <- as.data.frame.array( d.cum )

Then I tried to solve my problem within the panel function.
But now I had to set a value for ylim.

    test.xyplot <- function( data=barley, yr=1931, ymax=600, type='l', ... ){
        print( xyplot( data=data, subset=year==yr
            , type=type
            , panel=function( x, y, ... ){
                panel.xyplot( x, cumsum(y), ... )
            , ylim=c( 0, ymax )
            , yield ~ variety | site
            , scales=list( x=list( alternating=1, rot=90 ) )
            , ...

What could I do to get a dataframe containing the cumulative values
of ``yield'' which I could use to get the cumulative summary plots?

Thanks - Wolfram

More information about the R-help mailing list