Dear list, I have a data frame with a number of events (factor) and the times at which they occurred (continuous variable): event time A 10 A 12 B 15 A 17 C 13 ... Is it possible in R to make a plot against time of the cumulative frequency of occurrence of each event? This would be, a raising line for each factor. Regards, Dieter
Perhaps: par(mfrow=c(3,1)) lapply(tapply(df$time, df$events, ecdf), plot) On 15/10/2007, Dieter Vanderelst <dieter_vanderelst@emailengine.org> wrote:> > Dear list, > > I have a data frame with a number of events (factor) and the times at > which they occurred (continuous variable): > > event time > A 10 > A 12 > B 15 > A 17 > C 13 > ... > > Is it possible in R to make a plot against time of the cumulative > frequency of occurrence of each event? This would be, a raising line for > each factor. > > Regards, > Dieter > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Dieter Vanderelst wrote:> Dear list, > > I have a data frame with a number of events (factor) and the times at which they occurred (continuous variable): > > event time > A 10 > A 12 > B 15 > A 17 > C 13 > ... > > Is it possible in R to make a plot against time of the cumulative frequency of occurrence of each event? This would be, a raising line for each factor. >Hi Dieter, Henrique's solution is very elegant, but I thought you might find this one useful as well. event_codes<-LETTERS[1:5] sploogle<-data.frame(event=sample(event_codes,50,TRUE), time=sample(10:100,50)) sploogle<-sploogle[order(sploogle$time),] sploogle$event_count<-rep(NA,50) for(event_code in event_codes) sploogle$event_count[sploogle$event==event_code]<- 1:sum(sploogle$event==event_code) plot(sploogle$time[sploogle$event==event_codes[1]], sploogle$event_count[sploogle$event==event_codes[1]], main="Cumulative event count by time",xlim=c(1,max(sploogle$time)), ylim=c(1,max(sploogle$event_count)),type="b") for(i in 2:5) points(sploogle$time[sploogle$event==event_codes[i]], sploogle$event_count[sploogle$event==event_codes[i]], type="b",col=i,pch=i) legend(1,max(sploogle$event_count),event_codes,pch=1:5,col=1:5,lty=1) Jim