file1<-data.frame(
 col1=sample(c(50:52,220:229),1000,TRUE)*1000000,
 col2=sample(0:270,1000,TRUE),
 col3=runif(1000,50,80),col4=runif(1000,50,80),
 col5=sample(c("RED","GREEN","BLUE"),1000,TRUE))
file2<-data.frame(
 col1=sample(c(50:52,220:229),1000,TRUE)*1000000,
 col2=sample(0:270,1000,TRUE),
 col3=runif(1000,50,80),col4=runif(1000,50,80),
 col5=sample(c("RED","GREEN","BLUE"),1000,TRUE))
file1$col_group<-cut(file1$col2,breaks=c(0,20,50,70,271),
 right=FALSE)
file2$col_group<-cut(file2$col2,breaks=c(0,20,50,70,271),
 right=FALSE)
# get logical vectors that will pick out the different colors
reds1<-file1$col5=="RED"
reds2<-file2$col5=="RED"
greens1<-file1$col5=="GREEN"
greens2<-file2$col5=="GREEN"
blues1<-file1$col5=="BLUE"
blues2<-file2$col5=="BLUE"
# calculate the differences between col4 and col3
file1$col43<-file1$col4-file1$col3
file2$col43<-file2$col4-file2$col3
col_group11<-as.numeric(file1$col_group)==1
col_group12<-as.numeric(file1$col_group)==2
col_group13<-as.numeric(file1$col_group)==3
col_group14<-as.numeric(file1$col_group)==4
col_group21<-as.numeric(file2$col_group)==1
col_group22<-as.numeric(file2$col_group)==2
col_group23<-as.numeric(file2$col_group)==3
col_group24<-as.numeric(file2$col_group)==4
# need a wide display for this
x11(width=9)
# display the boxplots without 
boxplot(file1$col43[reds1&col_group11],
 file2$col43[reds2&col_group21],
 file1$col43[reds1&col_group12],
 file2$col43[reds2&col_group22],
 file1$col43[reds1&col_group13],
 file2$col43[reds2&col_group23],
 file1$col43[reds1&col_group14],
 file2$col43[reds2&col_group24],
 main="Comparison of RED col4 and col3 differences across col2 groups",
 ylab="MB",names=rep("",8),notch=TRUE,col=c("black","red"))
# add the x axis labels, staggered to avoid overlap
mtext(text=paste(c("file1","file2"),rep(levels(file1$col_group),each=2)),
 side=1,line=c(0.5,1.5),at=1:8)
