[R] lattice: cumsum and xyplot
I want to display cumulative summary functions with lattice. First I tried to get cumulated data: library(lattice) data(barley) 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 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] lattice: cumsum and xyplot
Hi! To get a data.frame as.data.frame(do.call(rbind,d.cum)) Sincerely Eryk *** REPLY SEPARATOR *** On 6/11/2004 at 9:17 AM Wolfram Fischer wrote: I want to display cumulative summary functions with lattice. First I tried to get cumulated data: library(lattice) data(barley) 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 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Dipl. bio-chem. Eryk Witold Wolski@MPI-Moleculare Genetic Ihnestrasse 63-73 14195 Berlin 'v' tel: 0049-30-83875219 / \ mail: [EMAIL PROTECTED]---W-Whttp://www.molgen.mpg.de/~wolski __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] lattice: cumsum and xyplot
--- In reply to: --- Date:11.06.04 09:33 (+0200) From:Wolski [EMAIL PROTECTED] Subject: Re: [R] lattice: cumsum and xyplot Hi! To get a data.frame as.data.frame(do.call(rbind,d.cum)) Thanks for this interesting hint. To get the lost names of factors again, I tried now the following solution: data(barley) d.cum - with( barley, by( yield, INDICES=list(site=site,year=year), FUN=function(x)x ) ) test.bylist2dataframe - function( bylist, col.names=NULL ){ veqq - as.data.frame( do.call( 'rbind', d.cum ) ) if( ! is.null( col.names ) ) colnames( veqq ) - col.names viqt.vars - names( dimnames(bylist) ) if( length( viqt.vars ) == 2 ){ veqq[,viqt.vars[1]] - as.factor( rep( dimnames( bylist )[[viqt.vars[1]]], times=dim(bylist)[2] ) ) veqq[,viqt.vars[2]] - as.factor( rep( dimnames( bylist )[[viqt.vars[2]]], each=dim(bylist)[1] ) ) } veqq } d.cum.dfr - test.bylist2dataframe( d.cum, col.names=unique( as.character( barley$variety ) ) ) But now I have the following problems: - ``d.cum.dfr'' is not yet normalised. - My solution works only for two ``INDICES''. So, what to do? - Wolfram *** REPLY SEPARATOR *** On 6/11/2004 at 9:17 AM Wolfram Fischer wrote: I want to display cumulative summary functions with lattice. First I tried to get cumulated data: library(lattice) data(barley) 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 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html