Skip to content

Instantly share code, notes, and snippets.

@RyanHope
Created August 24, 2012 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanHope/3444133 to your computer and use it in GitHub Desktop.
Save RyanHope/3444133 to your computer and use it in GitHub Desktop.
Cumulative Histogram
cumhist <- function(x, data=NULL, ...) {
terms<-as.character(x)
rhs<-terms[length(terms)]
splt<-strsplit(rhs,split="|", fixed=T)[[1]]
var<-splt[1]
grp<-splt[2]
lhs<-paste("ecdf(",var,")(",var,")", sep="")
ff<-paste(lhs, var, sep="~")
if(!is.na(grp)) {
ff<-paste(ff,grp,sep="|")
}
print(ff)
xyplot(as.formula(ff),data=data,...)
}
d1 = data.frame(latency=rnorm(1000,300,25), cond=rep("A", 1000))
d2 = data.frame(latency=rnorm(1000,200,10), cond=rep("B", 1000))
d = rbind(d1,d2)
p1 = cumhist(~latency,d)
p2 = cumhist(~latency|cond,d)
print(p1, split=c(1,1,1,2), more=TRUE)
print(p2, split=c(1,2,1,2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment