[R] help needed with boxplot

Jim Lemon jim at bitwrit.com.au
Wed Mar 24 12:03:38 CET 2010


On 03/24/2010 06:08 AM, kathy_BJ wrote:
>
> Thank you so much for help, Jim. But I didn't get any plot after I submit the
> job except below, which indicating the number of lines for the two inputs.
> What's the problem?
>
> Read 3360 records
> Read 3360 records
>
> I know I didn't confuse you.

Okay, let's make up some data and produce a set of boxplots.

file1<-data.frame(
  col1=sample(c(050000000:052000000,220000000:229000000),1000),
  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(050000000:052000000,220000000:229000000),1000),
  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)
reds1<-file1$col5=="RED"
reds2<-file2$col5=="RED"
greens1<-file1$col5=="GREEN"
greens2<-file2$col5=="GREEN"
blues1<-file1$col5=="BLUE"
blues2<-file2$col5=="BLUE"
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
x11(width=9)
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",
  names=rep("",8))
require(plotrix)
staxlab(at=1:8,
  labels=paste(c("file1","file2"),rep(levels(file1$col_group),each=2)))

This should produce a set of 8 boxplots comparing the medians, etc. of 
the differences of col4 and col3 between file1 and file 2 for all of the 
entries with col5="RED" across the levels of col_group. I don't know 
whether this is what you want, but it might get you started.

Jim



More information about the R-help mailing list