dat <- read.csv('//cdsnas/oebdbdms/Graphics/Datasets/CleanTrial.csv') base <- subset(dat, visit==2) eot <- subset(dat, visit==6) eot$binep <- ifelse(base$catvar-eot$catvar >= 2, 1, 0) # Suppose this actually is from two studies eot$study <- rep(c('Study 1','Study 2', 'Study 1', 'Study 2'), c(450,300,450,300)) ss <- with(eot, summarize(100*binep, llist(racef, study, trtf), smean.cl.normal)) ss$xaxis <- rep(1:4, each=4)+rep(c(-.1,.1), 8) names(ss)[4] <- 'binep' # Calculate counts and sample sizes for the table a1 <- with(eot[eot$study%in%'Study 1',], ftable(trtf, racef, binep)) xs1 <- a1[,2] n1 <- a1[,1]+a1[,2] a2 <- with(eot[eot$study%in%'Study 2',], ftable(trtf, racef, binep)) xs2 <- a2[,2] n2 <- a2[,1]+a2[,2] xpos <- c(.85,1.85,2.85,3.85,1.15,2.15,3.15,4.15) cols <- rep(c('black','seagreen2'),each=4) #png('C:/Research/Graphics/Graphs4Display/webpages/classes/pages/images/plottable.png', # width=700, height=700) new.line <- trellis.par.get('superpose.line') new.line$col <- c('black','seagreen2') new.line$lty <- c(1,1,1,1) new.symbol <- trellis.par.get('superpose.symbol') new.symbol$col <- c('black', 'seagreen2') new.symbol$pch <- c(1, 4, 16, 8) trellis.par.set('superpose.line', new.line) trellis.par.set('superpose.symbol', new.symbol) xYplot(Cbind(binep,Lower,Upper)~xaxis|study, groups=trtf, data=ss, xlab='Race', ylab='Percent Responders', ylim=c(ss$Lower-15,ss$Upper+1), aspect=1, scales=list(x=list(at=1:4, labels=(unique(ss$racef))), y=list(at=seq(20,60,10), labels=as.character(seq(20,60,10)))), key=list(type='p', points=list(pch=trellis.par.get('superpose.symbol')$pch[1:2], col=trellis.par.get('superpose.symbol')$col[1:2]), text=list(levels(base$trtf), col=trellis.par.get('superpose.symbol')$col[1:2]), columns=2, cex=1.25, title='Treatment')) # Overall means of the study oo <- with(eot, summarize(100*binep, llist(study,trtf), mean)) trellis.focus('panel',1,1, highlight=FALSE) panel.abline(h=oo[1:2,3], col=trellis.par.get('superpose.symbol')$col[1:2], lty=c(2,2)) for(i in 1:8){ ltext(x=xpos[i], y=8, labels=bquote(frac(.(xs1[i]),.(n1[i]))), cex=.95, col=cols[i]) } panel.abline(h=14, col='grey60') trellis.unfocus() trellis.focus('panel',2,1, highlight=FALSE) panel.abline(h=oo[3:4,3], col=trellis.par.get('superpose.symbol')$col[1:2], lty=c(2,2)) for(i in 1:8){ ltext(x=xpos[i], y=8, labels=bquote(frac(.(xs2[i]),.(n2[i]))), cex=.95, col=cols[i]) } panel.abline(h=14, col='grey60') trellis.unfocus() t1 <- with(eot[eot$study%in%'Study 1',], table(trtf)) t2 <- with(eot[eot$study%in%'Study 2',], table(trtf)) trellis.focus('strip', 1, 1, highlight=FALSE) ltext(x=0.025, y=.5, paste('N=', t1[1], sep=''), col=c('black'), adj=c(0,NA), cex=.9) ltext(x=0.975, y=.5, paste('N=', t1[2], sep=''), col=c('seagreen2'), adj=c(1,NA), cex=.9) trellis.unfocus() trellis.focus('strip', 2, 1, highlight=FALSE) ltext(x=0.025, y=.5, paste('N=', t2[1], sep=''), col=c('black'), adj=c(0,NA), cex=.9) ltext(x=0.975, y=.5, paste('N=', t2[2], sep=''), col=c('seagreen2'), adj=c(1,NA), cex=.9) trellis.unfocus() #dev.off()